@openclaw/codex 2026.7.1 → 2026.7.2-beta.2
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 +27 -3
- package/dist/app-server-policy-Scc-Wevo.js +49 -0
- package/dist/{attempt-notifications-BGsEIIDI.js → attempt-notifications-BFmNhqFl.js} +3 -6
- package/dist/auth-binding-C1czuHPA.js +62 -0
- package/dist/cli-metadata.js +20 -0
- package/dist/{app-server-policy-C968Kgin.js → command-formatters-Dq9InZUK.js} +39 -51
- package/dist/{command-handlers-Dv-pzAmg.js → command-handlers-IgqmL_kv.js} +161 -61
- package/dist/{compact-4mVBriKT.js → compact-DCTmg3id.js} +39 -10
- package/dist/computer-use-CPcU8TjG.js +685 -0
- package/dist/conversation-control-CGkBlfc5.js +286 -0
- package/dist/doctor-contract-api.js +120 -81
- package/dist/{provider-capabilities-CDnHbmUZ.js → dynamic-tools-C_1tEs34.js} +6109 -5725
- package/dist/harness.js +59 -15
- package/dist/index.js +1460 -269
- package/dist/{media-understanding-provider-BHOu9-Gg.js → media-understanding-provider-D31dOJwb.js} +32 -15
- package/dist/media-understanding-provider.js +1 -1
- package/dist/{models-DDmO1zwd.js → models-uh26C8QU.js} +5 -9
- package/dist/notification-correlation-KmfV4EkP.js +67 -0
- package/dist/plugin-app-cache-key-Ceb-lm2c.js +315 -0
- package/dist/{provider-zjPfx5Fs.js → rate-limits-DyXaYAxU.js} +10 -266
- package/dist/request-B_oQsCXy.js +157 -0
- package/dist/{run-attempt-FUyOjGCV.js → run-attempt-MLzoMe_m.js} +7395 -6430
- package/dist/runtime-artifact-C2ITXdhM.js +488 -0
- package/dist/{sandbox-guard-DA2TQfZW.js → sandbox-guard-D1Wky__S.js} +10 -1
- package/dist/{config-CYEDnLJ2.js → session-binding-h1mmCGnl.js} +985 -31
- package/dist/session-catalog-CEvoXWHA.js +2412 -0
- package/dist/session-cli-XsEuWb_C.js +175 -0
- package/dist/{shared-client-4ICy3U6d.js → shared-client-JiAnW6pc.js} +2193 -1319
- package/dist/{side-question-N4OaDer2.js → side-question-DqDvIwSU.js} +140 -70
- package/dist/{thread-lifecycle-qWE88Dn2.js → thread-lifecycle-CN_pPtPh.js} +1826 -1188
- package/dist/{protocol-validators-dZQ-UTOa.js → transcript-mirror-D9rTxx2P.js} +485 -2
- package/dist/transport-stdio-DXgGZ7Ib.js +88 -0
- package/dist/usage-D5Rohxoc.js +25 -0
- package/dist/{web-search-provider.runtime-BSlriav6.js → web-search-provider.runtime-CKVBn3fP.js} +3 -3
- package/npm-shrinkwrap.json +56 -30
- package/openclaw.plugin.json +177 -14
- package/package.json +8 -6
- package/dist/command-rpc-eLM_mtC7.js +0 -784
- package/dist/computer-use-Bmaz333N.js +0 -377
- package/dist/notification-correlation-Bo7KB3ks.js +0 -35
- package/dist/plugin-app-cache-key-BrhVdeEf.js +0 -98
- package/dist/prompt-overlay.js +0 -15
- package/dist/protocol-2POPqAY4.js +0 -13
- package/dist/provider-catalog.js +0 -79
- package/dist/provider-discovery.js +0 -34
- package/dist/provider.js +0 -2
- package/dist/request-BcJyl8KL.js +0 -36
- package/dist/session-binding-C1ZXdP-x.js +0 -627
|
@@ -0,0 +1,685 @@
|
|
|
1
|
+
import { E as resolveFirstExistingMacOSDesktopCodexBundledMarketplacePath, H as isCodexAppServerConnectionClosedError, U as isCodexAppServerIndeterminateRequestCancellationError, W as isCodexAppServerIndeterminateTransportError, a as getLeasedSharedCodexAppServerClient, c as releaseLeasedSharedCodexAppServerClient, h as acquireCodexNativeConfigFence, l as resolveCodexNativeConfigFenceKey } from "./shared-client-JiAnW6pc.js";
|
|
2
|
+
import { C as resolveCodexComputerUseConfig, b as resolveCodexAppServerRuntimeOptions } from "./session-binding-h1mmCGnl.js";
|
|
3
|
+
import { f as describeControlFailure } from "./command-formatters-Dq9InZUK.js";
|
|
4
|
+
import { r as requestCodexAppServerJson } from "./request-B_oQsCXy.js";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { runExec } from "openclaw/plugin-sdk/process-runtime";
|
|
7
|
+
//#region extensions/codex/src/app-server/computer-use.ts
|
|
8
|
+
/**
|
|
9
|
+
* Computer Use plugin/MCP readiness checks and optional install flow for Codex
|
|
10
|
+
* app-server sessions.
|
|
11
|
+
*/
|
|
12
|
+
var CodexComputerUseSetupError = class extends Error {
|
|
13
|
+
constructor(status) {
|
|
14
|
+
super(status.message);
|
|
15
|
+
this.name = "CodexComputerUseSetupError";
|
|
16
|
+
this.status = status;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const CURATED_MARKETPLACE_POLL_INTERVAL_MS = 2e3;
|
|
20
|
+
const COMPUTER_USE_MARKETPLACE_NAME_PRIORITY = [
|
|
21
|
+
"openai-bundled",
|
|
22
|
+
"openai-curated",
|
|
23
|
+
"local"
|
|
24
|
+
];
|
|
25
|
+
const COMPUTER_USE_LIVE_TEST_RETRY_COUNT = 1;
|
|
26
|
+
const COMPUTER_USE_LIVE_TEST_THREAD_NAME = "OpenClaw Computer Use readiness probe";
|
|
27
|
+
/** Reads Computer Use readiness without installing or mutating app-server state. */
|
|
28
|
+
async function readCodexComputerUseStatus(params = {}) {
|
|
29
|
+
const config = resolveComputerUseConfig(params);
|
|
30
|
+
if (!config.enabled) return disabledStatus(config);
|
|
31
|
+
try {
|
|
32
|
+
return await inspectCodexComputerUse({
|
|
33
|
+
...params,
|
|
34
|
+
computerUseConfig: config,
|
|
35
|
+
installPlugin: false
|
|
36
|
+
});
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return unavailableStatus(config, "check_failed", `Computer Use check failed: ${describeControlFailure(error)}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Ensures Computer Use is ready when enabled, optionally installing when config
|
|
43
|
+
* allows safe auto-install.
|
|
44
|
+
*/
|
|
45
|
+
async function ensureCodexComputerUse(params = {}) {
|
|
46
|
+
const config = resolveComputerUseConfig(params);
|
|
47
|
+
if (!config.enabled) return disabledStatus(config);
|
|
48
|
+
const status = await inspectCodexComputerUse({
|
|
49
|
+
...params,
|
|
50
|
+
computerUseConfig: config,
|
|
51
|
+
installPlugin: false
|
|
52
|
+
});
|
|
53
|
+
if (status.ready) return status;
|
|
54
|
+
if (isNonStrictLiveTestStartupAllowed(status, config)) return status;
|
|
55
|
+
if (config.autoInstall) {
|
|
56
|
+
const blockedAutoInstallStatus = blockUnsafeAutoInstallStatus(config);
|
|
57
|
+
if (blockedAutoInstallStatus) throw new CodexComputerUseSetupError(blockedAutoInstallStatus);
|
|
58
|
+
const installedStatus = await inspectCodexComputerUse({
|
|
59
|
+
...params,
|
|
60
|
+
computerUseConfig: config,
|
|
61
|
+
installPlugin: true
|
|
62
|
+
});
|
|
63
|
+
if (isNonStrictLiveTestStartupAllowed(installedStatus, config)) return installedStatus;
|
|
64
|
+
if (!installedStatus.ready) throw new CodexComputerUseSetupError(installedStatus);
|
|
65
|
+
return installedStatus;
|
|
66
|
+
}
|
|
67
|
+
if (!status.ready) throw new CodexComputerUseSetupError(status);
|
|
68
|
+
return status;
|
|
69
|
+
}
|
|
70
|
+
/** Forces Computer Use plugin installation and returns the ready status. */
|
|
71
|
+
async function installCodexComputerUse(params = {}) {
|
|
72
|
+
const config = resolveComputerUseConfig({
|
|
73
|
+
...params,
|
|
74
|
+
forceEnable: true,
|
|
75
|
+
overrides: {
|
|
76
|
+
...params.overrides,
|
|
77
|
+
enabled: true,
|
|
78
|
+
autoInstall: true
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const status = await inspectCodexComputerUse({
|
|
82
|
+
...params,
|
|
83
|
+
computerUseConfig: config,
|
|
84
|
+
installPlugin: true
|
|
85
|
+
});
|
|
86
|
+
if (!status.ready) throw new CodexComputerUseSetupError(status);
|
|
87
|
+
return status;
|
|
88
|
+
}
|
|
89
|
+
async function inspectCodexComputerUse(params) {
|
|
90
|
+
if (!params.installPlugin) return await inspectCodexComputerUseWithoutFence(params);
|
|
91
|
+
const runtime = params.client ? void 0 : resolveCodexAppServerRuntimeOptions({
|
|
92
|
+
pluginConfig: params.pluginConfig,
|
|
93
|
+
managedCommandOrder: "desktop-first"
|
|
94
|
+
});
|
|
95
|
+
const fenceKey = resolveCodexNativeConfigFenceKey({
|
|
96
|
+
client: params.client,
|
|
97
|
+
startOptions: runtime?.start,
|
|
98
|
+
agentDir: params.agentDir,
|
|
99
|
+
config: params.config
|
|
100
|
+
});
|
|
101
|
+
if (!fenceKey) return await inspectCodexComputerUseWithoutFence(params);
|
|
102
|
+
const release = await acquireCodexNativeConfigFence(fenceKey, {
|
|
103
|
+
signal: params.signal,
|
|
104
|
+
timeoutMs: params.timeoutMs ?? runtime?.requestTimeoutMs,
|
|
105
|
+
timeoutMessage: "Codex Computer Use install timed out waiting for native config",
|
|
106
|
+
abortMessage: "Codex Computer Use install aborted waiting for native config"
|
|
107
|
+
});
|
|
108
|
+
let releaseFenceOnReturn = true;
|
|
109
|
+
let leasedClient;
|
|
110
|
+
try {
|
|
111
|
+
let client = params.client;
|
|
112
|
+
if (!client && !params.request) {
|
|
113
|
+
if (!runtime) throw new Error("Computer Use install could not resolve its app-server runtime");
|
|
114
|
+
client = await getLeasedSharedCodexAppServerClient({
|
|
115
|
+
startOptions: runtime.start,
|
|
116
|
+
timeoutMs: params.timeoutMs ?? runtime.requestTimeoutMs,
|
|
117
|
+
config: params.config,
|
|
118
|
+
agentDir: params.agentDir,
|
|
119
|
+
abandonSignal: params.signal
|
|
120
|
+
});
|
|
121
|
+
leasedClient = client;
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
return await inspectCodexComputerUseWithoutFence({
|
|
125
|
+
...params,
|
|
126
|
+
...client ? {
|
|
127
|
+
client,
|
|
128
|
+
timeoutMs: params.timeoutMs ?? runtime?.requestTimeoutMs
|
|
129
|
+
} : {}
|
|
130
|
+
});
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (client && (isCodexAppServerIndeterminateRequestCancellationError(error) || isCodexAppServerIndeterminateTransportError(error) || isCodexAppServerConnectionClosedError(error))) {
|
|
133
|
+
releaseFenceOnReturn = false;
|
|
134
|
+
await client.closeAndRunAfterExit(release, "Computer Use config mutation");
|
|
135
|
+
}
|
|
136
|
+
throw error;
|
|
137
|
+
} finally {
|
|
138
|
+
if (leasedClient) releaseLeasedSharedCodexAppServerClient(leasedClient);
|
|
139
|
+
}
|
|
140
|
+
} finally {
|
|
141
|
+
if (releaseFenceOnReturn) release();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async function inspectCodexComputerUseWithoutFence(params) {
|
|
145
|
+
const request = createComputerUseRequest(params);
|
|
146
|
+
const repairComputerUseMcpChildren = params.repairComputerUseMcpChildren ?? (params.client ? () => killStaleComputerUseMcpChildren({ ancestorPid: params.client?.getTransportPid() }) : void 0);
|
|
147
|
+
if (params.installPlugin) await request("experimentalFeature/enablement/set", { enablement: { plugins: true } });
|
|
148
|
+
const marketplace = await resolveMarketplaceRef({
|
|
149
|
+
request,
|
|
150
|
+
config: params.computerUseConfig,
|
|
151
|
+
allowAdd: params.installPlugin,
|
|
152
|
+
signal: params.signal,
|
|
153
|
+
defaultBundledMarketplacePath: params.defaultBundledMarketplacePath,
|
|
154
|
+
defaultBundledMarketplacePathCandidates: params.defaultBundledMarketplacePathCandidates
|
|
155
|
+
});
|
|
156
|
+
if (!marketplace.marketplace) return unavailableStatus(params.computerUseConfig, "marketplace_missing", marketplace.message ?? `No Codex marketplace containing ${params.computerUseConfig.pluginName} is registered. Configure computerUse.marketplaceSource or computerUse.marketplacePath, then run /codex computer-use install.`);
|
|
157
|
+
const pluginInspection = await ensureComputerUsePlugin({
|
|
158
|
+
request,
|
|
159
|
+
config: params.computerUseConfig,
|
|
160
|
+
marketplace: marketplace.marketplace,
|
|
161
|
+
installPlugin: params.installPlugin
|
|
162
|
+
});
|
|
163
|
+
if (!pluginInspection.ok) return pluginInspection.status;
|
|
164
|
+
return await readComputerUseTools({
|
|
165
|
+
request,
|
|
166
|
+
config: params.computerUseConfig,
|
|
167
|
+
plugin: pluginInspection.plugin,
|
|
168
|
+
installPlugin: params.installPlugin,
|
|
169
|
+
repairComputerUseMcpChildren
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
async function ensureComputerUsePlugin(params) {
|
|
173
|
+
let plugin = await readComputerUsePlugin(params.request, params.marketplace, params.config.pluginName);
|
|
174
|
+
if (!plugin.summary.installed || !plugin.summary.enabled) {
|
|
175
|
+
if (!params.installPlugin) return {
|
|
176
|
+
ok: false,
|
|
177
|
+
status: statusFromPlugin({
|
|
178
|
+
config: params.config,
|
|
179
|
+
plugin,
|
|
180
|
+
tools: [],
|
|
181
|
+
reason: pluginSetupReason(plugin, params.marketplace),
|
|
182
|
+
message: pluginSetupMessage(params.config, plugin, params.marketplace)
|
|
183
|
+
})
|
|
184
|
+
};
|
|
185
|
+
if (params.marketplace.kind === "remote") return {
|
|
186
|
+
ok: false,
|
|
187
|
+
status: statusFromPlugin({
|
|
188
|
+
config: params.config,
|
|
189
|
+
plugin,
|
|
190
|
+
tools: [],
|
|
191
|
+
reason: "remote_install_unsupported",
|
|
192
|
+
message: remoteInstallUnsupportedMessage(plugin, params.marketplace)
|
|
193
|
+
})
|
|
194
|
+
};
|
|
195
|
+
await params.request("plugin/install", pluginRequestParams(params.marketplace, params.config.pluginName));
|
|
196
|
+
await reloadMcpServers(params.request);
|
|
197
|
+
plugin = await readComputerUsePlugin(params.request, params.marketplace, params.config.pluginName);
|
|
198
|
+
}
|
|
199
|
+
if (!plugin.summary.installed || !plugin.summary.enabled) return {
|
|
200
|
+
ok: false,
|
|
201
|
+
status: statusFromPlugin({
|
|
202
|
+
config: params.config,
|
|
203
|
+
plugin,
|
|
204
|
+
tools: [],
|
|
205
|
+
reason: pluginSetupReason(plugin, params.marketplace),
|
|
206
|
+
message: pluginSetupMessage(params.config, plugin, params.marketplace)
|
|
207
|
+
})
|
|
208
|
+
};
|
|
209
|
+
return {
|
|
210
|
+
ok: true,
|
|
211
|
+
plugin
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
async function readComputerUseTools(params) {
|
|
215
|
+
let server = await readMcpServerStatus(params.request, params.config.mcpServerName);
|
|
216
|
+
if (!server && params.installPlugin) {
|
|
217
|
+
await reloadMcpServers(params.request);
|
|
218
|
+
server = await readMcpServerStatus(params.request, params.config.mcpServerName);
|
|
219
|
+
}
|
|
220
|
+
if (!server) return statusFromPlugin({
|
|
221
|
+
config: params.config,
|
|
222
|
+
plugin: params.plugin,
|
|
223
|
+
tools: [],
|
|
224
|
+
reason: "mcp_missing",
|
|
225
|
+
message: `Computer Use is installed, but the ${params.config.mcpServerName} MCP server is not available.`
|
|
226
|
+
});
|
|
227
|
+
const status = statusFromPlugin({
|
|
228
|
+
config: params.config,
|
|
229
|
+
plugin: params.plugin,
|
|
230
|
+
tools: Object.keys(server.tools).toSorted(),
|
|
231
|
+
reason: "ready",
|
|
232
|
+
message: "Computer Use is ready."
|
|
233
|
+
});
|
|
234
|
+
const { liveTest, repair } = await runCodexComputerUseLiveTest({
|
|
235
|
+
request: params.request,
|
|
236
|
+
config: params.config,
|
|
237
|
+
repairComputerUseMcpChildren: params.repairComputerUseMcpChildren
|
|
238
|
+
});
|
|
239
|
+
const compatibilityStartupAllowed = !liveTest.ok && !params.config.strictReadiness;
|
|
240
|
+
return {
|
|
241
|
+
...status,
|
|
242
|
+
ready: liveTest.ok,
|
|
243
|
+
reason: liveTest.ok ? "ready" : "live_test_failed",
|
|
244
|
+
liveTest,
|
|
245
|
+
...repair ? { repair } : {},
|
|
246
|
+
warnings: [
|
|
247
|
+
...status.warnings,
|
|
248
|
+
...repair?.warnings ?? [],
|
|
249
|
+
...compatibilityStartupAllowed ? ["Computer Use live test failed, but compatibility startup remains enabled; set computerUse.strictReadiness to true to fail closed."] : []
|
|
250
|
+
],
|
|
251
|
+
message: liveTest.ok ? "Computer Use is ready." : compatibilityStartupAllowed ? `${liveTest.message} Startup is allowed because computerUse.strictReadiness is false.` : liveTest.message
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function isNonStrictLiveTestStartupAllowed(status, config) {
|
|
255
|
+
return !config.strictReadiness && status.reason === "live_test_failed" && status.installed && status.pluginEnabled && status.mcpServerAvailable && status.installation.ok && status.exposure.ok;
|
|
256
|
+
}
|
|
257
|
+
async function runCodexComputerUseLiveTest(params) {
|
|
258
|
+
const startedAt = Date.now();
|
|
259
|
+
let lastError;
|
|
260
|
+
let repair;
|
|
261
|
+
for (let attempt = 0; attempt <= COMPUTER_USE_LIVE_TEST_RETRY_COUNT; attempt += 1) {
|
|
262
|
+
let threadId;
|
|
263
|
+
try {
|
|
264
|
+
threadId = (await params.request("thread/start", {
|
|
265
|
+
input: [],
|
|
266
|
+
developerInstructions: COMPUTER_USE_LIVE_TEST_THREAD_NAME,
|
|
267
|
+
sandbox: "danger-full-access",
|
|
268
|
+
approvalPolicy: "never",
|
|
269
|
+
ephemeral: true
|
|
270
|
+
}, { timeoutMs: params.config.liveTestTimeoutMs })).thread.id;
|
|
271
|
+
await params.request("mcpServer/tool/call", {
|
|
272
|
+
threadId,
|
|
273
|
+
server: params.config.mcpServerName,
|
|
274
|
+
tool: "list_apps",
|
|
275
|
+
arguments: {}
|
|
276
|
+
}, { timeoutMs: params.config.toolCallTimeoutMs });
|
|
277
|
+
return {
|
|
278
|
+
liveTest: {
|
|
279
|
+
status: "passed",
|
|
280
|
+
ok: true,
|
|
281
|
+
attempted: true,
|
|
282
|
+
attempts: attempt + 1,
|
|
283
|
+
timeoutMs: params.config.liveTestTimeoutMs,
|
|
284
|
+
retried: attempt > 0,
|
|
285
|
+
repaired: Boolean(repair?.attempted),
|
|
286
|
+
durationMs: Math.max(0, Date.now() - startedAt),
|
|
287
|
+
message: "Computer Use live test passed."
|
|
288
|
+
},
|
|
289
|
+
...repair ? { repair } : {}
|
|
290
|
+
};
|
|
291
|
+
} catch (error) {
|
|
292
|
+
lastError = error;
|
|
293
|
+
if (attempt >= COMPUTER_USE_LIVE_TEST_RETRY_COUNT) break;
|
|
294
|
+
if (params.config.autoRepair) repair = params.repairComputerUseMcpChildren ? await params.repairComputerUseMcpChildren() : scopedRepairUnavailableStatus();
|
|
295
|
+
} finally {
|
|
296
|
+
if (threadId) await cleanupComputerUseProbeThread(params.request, threadId, params.config);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const errorMessage = describeControlFailure(lastError);
|
|
300
|
+
return {
|
|
301
|
+
liveTest: {
|
|
302
|
+
status: "failed",
|
|
303
|
+
ok: false,
|
|
304
|
+
attempted: true,
|
|
305
|
+
attempts: 2,
|
|
306
|
+
timeoutMs: params.config.liveTestTimeoutMs,
|
|
307
|
+
retried: true,
|
|
308
|
+
repaired: Boolean(repair?.attempted),
|
|
309
|
+
durationMs: Math.max(0, Date.now() - startedAt),
|
|
310
|
+
message: `Computer Use live test failed after 2 attempts: ${errorMessage}`,
|
|
311
|
+
error: errorMessage
|
|
312
|
+
},
|
|
313
|
+
...repair ? { repair } : {}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
async function cleanupComputerUseProbeThread(request, threadId, config) {
|
|
317
|
+
await Promise.allSettled([request("thread/unsubscribe", { threadId }, { timeoutMs: config.liveTestTimeoutMs }), request("thread/archive", { threadId }, { timeoutMs: config.liveTestTimeoutMs })]);
|
|
318
|
+
}
|
|
319
|
+
function scopedRepairUnavailableStatus() {
|
|
320
|
+
return {
|
|
321
|
+
attempted: false,
|
|
322
|
+
killedPids: [],
|
|
323
|
+
warnings: ["Computer Use auto-repair skipped because no scoped Codex app-server process was available."],
|
|
324
|
+
message: "Computer Use stale child repair requires a scoped local app-server PID."
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
async function resolveMarketplaceRef(params) {
|
|
328
|
+
let preferredMarketplaceName = params.config.marketplaceName;
|
|
329
|
+
if (params.config.marketplaceSource && params.allowAdd) {
|
|
330
|
+
const added = await params.request("marketplace/add", { source: params.config.marketplaceSource });
|
|
331
|
+
preferredMarketplaceName ??= added.marketplaceName;
|
|
332
|
+
}
|
|
333
|
+
if (params.config.marketplacePath) return { marketplace: preferredMarketplaceName ? {
|
|
334
|
+
kind: "local",
|
|
335
|
+
name: preferredMarketplaceName,
|
|
336
|
+
path: params.config.marketplacePath
|
|
337
|
+
} : {
|
|
338
|
+
kind: "local",
|
|
339
|
+
path: params.config.marketplacePath
|
|
340
|
+
} };
|
|
341
|
+
let candidates = await listComputerUseMarketplaceCandidates(params.request, params.config);
|
|
342
|
+
const bundledMarketplacePath = resolveBundledComputerUseMarketplacePath(params);
|
|
343
|
+
if (candidates.length === 0 && bundledMarketplacePath && shouldAddBundledComputerUseMarketplace(params)) {
|
|
344
|
+
const added = await params.request("marketplace/add", { source: bundledMarketplacePath });
|
|
345
|
+
preferredMarketplaceName ??= added.marketplaceName;
|
|
346
|
+
candidates = await listComputerUseMarketplaceCandidates(params.request, params.config);
|
|
347
|
+
}
|
|
348
|
+
const waitUntil = marketplaceDiscoveryWaitUntil(params);
|
|
349
|
+
while (candidates.length === 0) {
|
|
350
|
+
if (Date.now() >= waitUntil) break;
|
|
351
|
+
await delay(Math.min(CURATED_MARKETPLACE_POLL_INTERVAL_MS, waitUntil - Date.now()), params.signal);
|
|
352
|
+
candidates = await listComputerUseMarketplaceCandidates(params.request, params.config);
|
|
353
|
+
}
|
|
354
|
+
if (preferredMarketplaceName) {
|
|
355
|
+
const preferred = candidates.find((candidate) => candidate.name === preferredMarketplaceName);
|
|
356
|
+
if (preferred) return { marketplace: preferred };
|
|
357
|
+
return { message: `Configured Codex marketplace ${preferredMarketplaceName} was not found or does not contain ${params.config.pluginName}. Run /codex computer-use install with a source or path to install from a new marketplace.` };
|
|
358
|
+
}
|
|
359
|
+
if (candidates.length > 1) {
|
|
360
|
+
const preferred = chooseKnownComputerUseMarketplace(candidates);
|
|
361
|
+
if (preferred) return { marketplace: preferred };
|
|
362
|
+
return { message: `Multiple Codex marketplaces contain ${params.config.pluginName}. Configure computerUse.marketplaceName or computerUse.marketplacePath to choose one.` };
|
|
363
|
+
}
|
|
364
|
+
if (params.config.marketplaceSource && !params.allowAdd && candidates.length === 0) return { message: "Computer Use marketplace source is configured but has not been registered. Run /codex computer-use install to register it." };
|
|
365
|
+
const marketplace = candidates[0];
|
|
366
|
+
return marketplace ? { marketplace } : {};
|
|
367
|
+
}
|
|
368
|
+
async function listComputerUseMarketplaceCandidates(request, config) {
|
|
369
|
+
return findComputerUseMarketplaces(await request("plugin/list", { cwds: [] }), config.pluginName);
|
|
370
|
+
}
|
|
371
|
+
function blockUnsafeAutoInstallStatus(config) {
|
|
372
|
+
if (!config.marketplaceSource) return;
|
|
373
|
+
return unavailableStatus(config, "auto_install_blocked", "Computer Use auto-install only uses marketplaces Codex app-server has already discovered. Run /codex computer-use install to install from a configured marketplace source.");
|
|
374
|
+
}
|
|
375
|
+
function shouldAddBundledComputerUseMarketplace(params) {
|
|
376
|
+
return params.allowAdd && !params.config.marketplaceSource && !params.config.marketplacePath && !params.config.marketplaceName && Boolean(resolveBundledComputerUseMarketplacePath(params));
|
|
377
|
+
}
|
|
378
|
+
function resolveBundledComputerUseMarketplacePath(params) {
|
|
379
|
+
if (params.defaultBundledMarketplacePath) return existsSync(params.defaultBundledMarketplacePath) ? params.defaultBundledMarketplacePath : void 0;
|
|
380
|
+
return resolveFirstExistingMacOSDesktopCodexBundledMarketplacePath({ candidates: params.defaultBundledMarketplacePathCandidates });
|
|
381
|
+
}
|
|
382
|
+
function findComputerUseMarketplaces(listed, pluginName) {
|
|
383
|
+
return listed.marketplaces.filter((marketplace) => marketplace.plugins.some((plugin) => plugin.name === pluginName || plugin.id === pluginName || plugin.id === `${pluginName}@${marketplace.name}`)).map((marketplace) => {
|
|
384
|
+
if (marketplace.path) return {
|
|
385
|
+
kind: "local",
|
|
386
|
+
name: marketplace.name,
|
|
387
|
+
path: marketplace.path
|
|
388
|
+
};
|
|
389
|
+
return {
|
|
390
|
+
kind: "remote",
|
|
391
|
+
name: marketplace.name,
|
|
392
|
+
remoteMarketplaceName: marketplace.name
|
|
393
|
+
};
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
function chooseKnownComputerUseMarketplace(candidates) {
|
|
397
|
+
for (const marketplaceName of COMPUTER_USE_MARKETPLACE_NAME_PRIORITY) {
|
|
398
|
+
const candidate = candidates.find((marketplace) => marketplace.name === marketplaceName);
|
|
399
|
+
if (candidate) return candidate;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
function marketplaceDiscoveryWaitUntil(params) {
|
|
403
|
+
if (params.allowAdd && !params.config.marketplaceSource && !params.config.marketplacePath && !params.config.marketplaceName) return Date.now() + params.config.marketplaceDiscoveryTimeoutMs;
|
|
404
|
+
return 0;
|
|
405
|
+
}
|
|
406
|
+
async function delay(ms, signal) {
|
|
407
|
+
if (signal?.aborted) throw abortError(signal);
|
|
408
|
+
await new Promise((resolve, reject) => {
|
|
409
|
+
const onAbort = () => {
|
|
410
|
+
clearTimeout(timer);
|
|
411
|
+
signal?.removeEventListener("abort", onAbort);
|
|
412
|
+
reject(abortError(signal));
|
|
413
|
+
};
|
|
414
|
+
const timer = setTimeout(() => {
|
|
415
|
+
signal?.removeEventListener("abort", onAbort);
|
|
416
|
+
resolve();
|
|
417
|
+
}, ms);
|
|
418
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
function abortError(signal) {
|
|
422
|
+
const reason = signal?.reason;
|
|
423
|
+
return reason instanceof Error ? reason : /* @__PURE__ */ new Error("Computer Use setup was aborted.");
|
|
424
|
+
}
|
|
425
|
+
async function readComputerUsePlugin(request, marketplace, pluginName) {
|
|
426
|
+
return (await request("plugin/read", pluginRequestParams(marketplace, pluginName))).plugin;
|
|
427
|
+
}
|
|
428
|
+
async function readMcpServerStatus(request, serverName) {
|
|
429
|
+
let cursor;
|
|
430
|
+
do {
|
|
431
|
+
const response = await request("mcpServerStatus/list", {
|
|
432
|
+
cursor,
|
|
433
|
+
limit: 100,
|
|
434
|
+
detail: "toolsAndAuthOnly"
|
|
435
|
+
});
|
|
436
|
+
const found = response.data.find((server) => server.name === serverName);
|
|
437
|
+
if (found) return found;
|
|
438
|
+
cursor = response.nextCursor;
|
|
439
|
+
} while (cursor);
|
|
440
|
+
}
|
|
441
|
+
async function reloadMcpServers(request) {
|
|
442
|
+
await request("config/mcpServer/reload", void 0);
|
|
443
|
+
}
|
|
444
|
+
function pluginRequestParams(marketplace, pluginName) {
|
|
445
|
+
return {
|
|
446
|
+
...marketplace.kind === "local" ? { marketplacePath: marketplace.path } : {},
|
|
447
|
+
...marketplace.kind === "remote" ? { remoteMarketplaceName: marketplace.remoteMarketplaceName } : {},
|
|
448
|
+
pluginName
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
function pluginSetupReason(plugin, marketplace) {
|
|
452
|
+
if (marketplace.kind === "remote") return "remote_install_unsupported";
|
|
453
|
+
return plugin.summary.installed ? "plugin_disabled" : "plugin_not_installed";
|
|
454
|
+
}
|
|
455
|
+
function pluginSetupMessage(config, plugin, marketplace) {
|
|
456
|
+
if (marketplace.kind === "remote") return remoteInstallUnsupportedMessage(plugin, marketplace);
|
|
457
|
+
if (!plugin.summary.installed) return "Computer Use is available but not installed. Run /codex computer-use install or enable computerUse.autoInstall.";
|
|
458
|
+
return `Computer Use is installed, but the ${config.pluginName} plugin is disabled. Run /codex computer-use install or enable computerUse.autoInstall to re-enable it.`;
|
|
459
|
+
}
|
|
460
|
+
function remoteInstallUnsupportedMessage(plugin, marketplace) {
|
|
461
|
+
const marketplaceName = marketplace.name ?? plugin.marketplaceName;
|
|
462
|
+
return `Computer Use is ${plugin.summary.installed ? "installed but disabled" : "available"} in remote Codex marketplace ${marketplaceName}, but Codex app-server does not support remote plugin install yet. Configure computerUse.marketplaceSource or computerUse.marketplacePath for a local marketplace, then run /codex computer-use install.`;
|
|
463
|
+
}
|
|
464
|
+
function statusFromPlugin(params) {
|
|
465
|
+
return {
|
|
466
|
+
enabled: true,
|
|
467
|
+
ready: params.plugin.summary.installed && params.plugin.summary.enabled && params.tools.length > 0,
|
|
468
|
+
reason: params.reason,
|
|
469
|
+
installed: params.plugin.summary.installed,
|
|
470
|
+
pluginEnabled: params.plugin.summary.enabled,
|
|
471
|
+
mcpServerAvailable: params.tools.length > 0,
|
|
472
|
+
pluginName: params.config.pluginName,
|
|
473
|
+
mcpServerName: params.config.mcpServerName,
|
|
474
|
+
marketplaceName: params.plugin.marketplaceName,
|
|
475
|
+
...params.plugin.marketplacePath ? { marketplacePath: params.plugin.marketplacePath } : {},
|
|
476
|
+
tools: params.tools,
|
|
477
|
+
installation: installationStatusFromPlugin(params.plugin, params.message),
|
|
478
|
+
exposure: exposureStatusFromTools(params.config, params.tools),
|
|
479
|
+
liveTest: skippedLiveTestStatus(params.config, "Computer Use live test was not run."),
|
|
480
|
+
warnings: pluginWarnings(params.plugin),
|
|
481
|
+
message: params.message
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function disabledStatus(config) {
|
|
485
|
+
return {
|
|
486
|
+
enabled: false,
|
|
487
|
+
ready: false,
|
|
488
|
+
reason: "disabled",
|
|
489
|
+
installed: false,
|
|
490
|
+
pluginEnabled: false,
|
|
491
|
+
mcpServerAvailable: false,
|
|
492
|
+
pluginName: config.pluginName,
|
|
493
|
+
mcpServerName: config.mcpServerName,
|
|
494
|
+
tools: [],
|
|
495
|
+
installation: {
|
|
496
|
+
status: "disabled",
|
|
497
|
+
ok: false,
|
|
498
|
+
message: "Computer Use is disabled."
|
|
499
|
+
},
|
|
500
|
+
exposure: {
|
|
501
|
+
status: "skipped",
|
|
502
|
+
ok: false,
|
|
503
|
+
message: "MCP exposure was not checked because Computer Use is disabled."
|
|
504
|
+
},
|
|
505
|
+
liveTest: skippedLiveTestStatus(config, "Computer Use live test was not run because Computer Use is disabled."),
|
|
506
|
+
warnings: [],
|
|
507
|
+
message: "Computer Use is disabled."
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
function unavailableStatus(config, reason, message) {
|
|
511
|
+
return {
|
|
512
|
+
enabled: true,
|
|
513
|
+
ready: false,
|
|
514
|
+
reason,
|
|
515
|
+
installed: false,
|
|
516
|
+
pluginEnabled: false,
|
|
517
|
+
mcpServerAvailable: false,
|
|
518
|
+
pluginName: config.pluginName,
|
|
519
|
+
mcpServerName: config.mcpServerName,
|
|
520
|
+
...config.marketplaceName ? { marketplaceName: config.marketplaceName } : {},
|
|
521
|
+
...config.marketplacePath ? { marketplacePath: config.marketplacePath } : {},
|
|
522
|
+
tools: [],
|
|
523
|
+
installation: {
|
|
524
|
+
status: reason === "marketplace_missing" ? "marketplace_missing" : "not_installed",
|
|
525
|
+
ok: false,
|
|
526
|
+
message
|
|
527
|
+
},
|
|
528
|
+
exposure: {
|
|
529
|
+
status: "skipped",
|
|
530
|
+
ok: false,
|
|
531
|
+
message: "MCP exposure was not checked because Computer Use installation is not ready."
|
|
532
|
+
},
|
|
533
|
+
liveTest: skippedLiveTestStatus(config, "Computer Use live test was not run because installation is not ready."),
|
|
534
|
+
warnings: [],
|
|
535
|
+
message
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
function installationStatusFromPlugin(plugin, message) {
|
|
539
|
+
if (!plugin.summary.installed) return {
|
|
540
|
+
status: "not_installed",
|
|
541
|
+
ok: false,
|
|
542
|
+
message
|
|
543
|
+
};
|
|
544
|
+
if (!plugin.summary.enabled) return {
|
|
545
|
+
status: "installed_disabled",
|
|
546
|
+
ok: false,
|
|
547
|
+
message
|
|
548
|
+
};
|
|
549
|
+
return {
|
|
550
|
+
status: "installed",
|
|
551
|
+
ok: true,
|
|
552
|
+
message: "Computer Use plugin is installed and enabled."
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
function exposureStatusFromTools(config, tools) {
|
|
556
|
+
if (tools.length === 0) return {
|
|
557
|
+
status: "missing",
|
|
558
|
+
ok: false,
|
|
559
|
+
message: `Computer Use MCP server ${config.mcpServerName} is not exposed.`
|
|
560
|
+
};
|
|
561
|
+
return {
|
|
562
|
+
status: "available",
|
|
563
|
+
ok: true,
|
|
564
|
+
message: `Computer Use MCP server ${config.mcpServerName} exposes ${tools.length} tools.`
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
function skippedLiveTestStatus(config, message) {
|
|
568
|
+
return {
|
|
569
|
+
status: "skipped",
|
|
570
|
+
ok: false,
|
|
571
|
+
attempted: false,
|
|
572
|
+
attempts: 0,
|
|
573
|
+
timeoutMs: config.liveTestTimeoutMs,
|
|
574
|
+
retried: false,
|
|
575
|
+
repaired: false,
|
|
576
|
+
message
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
function pluginWarnings(plugin) {
|
|
580
|
+
const warnings = [];
|
|
581
|
+
const source = plugin.summary.source;
|
|
582
|
+
if (source && typeof source === "object" && "type" in source && source.type === "remote") warnings.push("Computer Use plugin is resolved from a remote marketplace; live local bundles are preferred.");
|
|
583
|
+
return warnings;
|
|
584
|
+
}
|
|
585
|
+
async function killStaleComputerUseMcpChildren(options = {}) {
|
|
586
|
+
if (process.platform !== "darwin") return {
|
|
587
|
+
attempted: true,
|
|
588
|
+
killedPids: [],
|
|
589
|
+
warnings: [`Computer Use stale child repair is currently macOS-only, not ${process.platform}.`],
|
|
590
|
+
message: "Computer Use stale child repair skipped on this platform."
|
|
591
|
+
};
|
|
592
|
+
if (!options.ancestorPid || !Number.isSafeInteger(options.ancestorPid) || options.ancestorPid <= 0) return scopedRepairUnavailableStatus();
|
|
593
|
+
let stdout;
|
|
594
|
+
try {
|
|
595
|
+
stdout = (await runExec("/bin/ps", ["-axo", "pid=,ppid=,command="], {
|
|
596
|
+
logOutput: false,
|
|
597
|
+
maxBuffer: 5 * 1024 * 1024
|
|
598
|
+
})).stdout;
|
|
599
|
+
} catch (error) {
|
|
600
|
+
return {
|
|
601
|
+
attempted: true,
|
|
602
|
+
killedPids: [],
|
|
603
|
+
warnings: [`Could not list processes for Computer Use repair: ${describeControlFailure(error)}`],
|
|
604
|
+
message: "Computer Use stale child repair could not inspect running processes."
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
const killedPids = [];
|
|
608
|
+
const warnings = [];
|
|
609
|
+
const processInfos = parsePsOutput(stdout);
|
|
610
|
+
for (const processInfo of processInfos) {
|
|
611
|
+
if (!isStaleComputerUseMcpChild(processInfo.command)) continue;
|
|
612
|
+
if (!isDescendantOfPid(processInfo.pid, options.ancestorPid, processInfos)) continue;
|
|
613
|
+
try {
|
|
614
|
+
process.kill(processInfo.pid, "SIGTERM");
|
|
615
|
+
killedPids.push(processInfo.pid);
|
|
616
|
+
} catch (error) {
|
|
617
|
+
warnings.push(`Could not terminate stale Computer Use MCP child pid ${processInfo.pid}: ${describeControlFailure(error)}`);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
return {
|
|
621
|
+
attempted: true,
|
|
622
|
+
killedPids,
|
|
623
|
+
warnings,
|
|
624
|
+
message: killedPids.length === 0 ? "No stale Computer Use MCP children were found under the scoped Codex app-server process." : `Terminated ${killedPids.length} stale Computer Use MCP child process${killedPids.length === 1 ? "" : "es"} under the scoped Codex app-server process.`
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
function parsePsOutput(stdout) {
|
|
628
|
+
return stdout.split(/\r?\n/u).flatMap((line) => {
|
|
629
|
+
const match = /^\s*(\d+)\s+(\d+)\s+(.+)$/u.exec(line);
|
|
630
|
+
if (!match) return [];
|
|
631
|
+
return [{
|
|
632
|
+
pid: Number(match[1]),
|
|
633
|
+
ppid: Number(match[2]),
|
|
634
|
+
command: match[3] ?? ""
|
|
635
|
+
}];
|
|
636
|
+
}).filter((processInfo) => Number.isSafeInteger(processInfo.pid) && processInfo.pid > 0 && Number.isSafeInteger(processInfo.ppid) && processInfo.ppid >= 0);
|
|
637
|
+
}
|
|
638
|
+
function isStaleComputerUseMcpChild(command) {
|
|
639
|
+
return command.includes("SkyComputerUseClient") && /(?:^|\s)mcp(?:\s|$)/u.test(command);
|
|
640
|
+
}
|
|
641
|
+
function isDescendantOfPid(pid, ancestorPid, processInfos) {
|
|
642
|
+
const parents = new Map(processInfos.map((processInfo) => [processInfo.pid, processInfo.ppid]));
|
|
643
|
+
const seen = /* @__PURE__ */ new Set();
|
|
644
|
+
let current = pid;
|
|
645
|
+
while (!seen.has(current)) {
|
|
646
|
+
seen.add(current);
|
|
647
|
+
const parent = parents.get(current);
|
|
648
|
+
if (!parent || parent <= 0) return false;
|
|
649
|
+
if (parent === ancestorPid) return true;
|
|
650
|
+
current = parent;
|
|
651
|
+
}
|
|
652
|
+
return false;
|
|
653
|
+
}
|
|
654
|
+
function createComputerUseRequest(params) {
|
|
655
|
+
if (params.request) return params.request;
|
|
656
|
+
if (params.client) return async (method, requestParams, options) => await params.client.request(method, requestParams, {
|
|
657
|
+
timeoutMs: options?.timeoutMs ?? params.timeoutMs,
|
|
658
|
+
signal: params.signal
|
|
659
|
+
});
|
|
660
|
+
const runtime = resolveCodexAppServerRuntimeOptions({
|
|
661
|
+
pluginConfig: params.pluginConfig,
|
|
662
|
+
managedCommandOrder: "desktop-first"
|
|
663
|
+
});
|
|
664
|
+
return async (method, requestParams, options) => await requestCodexAppServerJson({
|
|
665
|
+
method,
|
|
666
|
+
requestParams,
|
|
667
|
+
timeoutMs: options?.timeoutMs ?? params.timeoutMs ?? runtime.requestTimeoutMs,
|
|
668
|
+
pluginConfig: params.pluginConfig,
|
|
669
|
+
startOptions: runtime.start,
|
|
670
|
+
config: params.config,
|
|
671
|
+
agentDir: params.agentDir
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
function resolveComputerUseConfig(params) {
|
|
675
|
+
const overrides = params.forceEnable ? {
|
|
676
|
+
...params.overrides,
|
|
677
|
+
enabled: true
|
|
678
|
+
} : params.overrides;
|
|
679
|
+
return resolveCodexComputerUseConfig({
|
|
680
|
+
pluginConfig: params.pluginConfig,
|
|
681
|
+
overrides
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
//#endregion
|
|
685
|
+
export { runCodexComputerUseLiveTest as a, readCodexComputerUseStatus as i, installCodexComputerUse as n, killStaleComputerUseMcpChildren as r, ensureCodexComputerUse as t };
|