@kodelyth/codex 2026.5.42 → 2026.6.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.
Files changed (138) hide show
  1. package/package.json +16 -1
  2. package/doctor-contract-api.test.ts +0 -44
  3. package/doctor-contract-api.ts +0 -68
  4. package/harness.ts +0 -72
  5. package/index.test.ts +0 -230
  6. package/index.ts +0 -66
  7. package/media-understanding-provider.test.ts +0 -486
  8. package/media-understanding-provider.ts +0 -521
  9. package/prompt-overlay-runtime-contract.test.ts +0 -48
  10. package/prompt-overlay.ts +0 -21
  11. package/provider-catalog.ts +0 -83
  12. package/provider-discovery.ts +0 -45
  13. package/provider.test.ts +0 -384
  14. package/provider.ts +0 -243
  15. package/src/app-server/app-inventory-cache.test.ts +0 -176
  16. package/src/app-server/app-inventory-cache.ts +0 -324
  17. package/src/app-server/approval-bridge.test.ts +0 -1471
  18. package/src/app-server/approval-bridge.ts +0 -1211
  19. package/src/app-server/auth-bridge.test.ts +0 -1449
  20. package/src/app-server/auth-bridge.ts +0 -614
  21. package/src/app-server/auth-profile-runtime-contract.test.ts +0 -239
  22. package/src/app-server/capabilities.ts +0 -27
  23. package/src/app-server/client-factory.ts +0 -24
  24. package/src/app-server/client.test.ts +0 -563
  25. package/src/app-server/client.ts +0 -715
  26. package/src/app-server/compact.test.ts +0 -710
  27. package/src/app-server/compact.ts +0 -500
  28. package/src/app-server/computer-use.test.ts +0 -788
  29. package/src/app-server/computer-use.ts +0 -683
  30. package/src/app-server/config.test.ts +0 -879
  31. package/src/app-server/config.ts +0 -1038
  32. package/src/app-server/context-engine-projection.test.ts +0 -252
  33. package/src/app-server/context-engine-projection.ts +0 -403
  34. package/src/app-server/delivery-no-reply-runtime-contract.test.ts +0 -80
  35. package/src/app-server/dynamic-tool-diagnostics.ts +0 -73
  36. package/src/app-server/dynamic-tool-profile.ts +0 -69
  37. package/src/app-server/dynamic-tools.test.ts +0 -1302
  38. package/src/app-server/dynamic-tools.ts +0 -623
  39. package/src/app-server/elicitation-bridge.test.ts +0 -1056
  40. package/src/app-server/elicitation-bridge.ts +0 -783
  41. package/src/app-server/event-projector.test.ts +0 -2668
  42. package/src/app-server/event-projector.ts +0 -2057
  43. package/src/app-server/image-payload-sanitizer.test.ts +0 -49
  44. package/src/app-server/image-payload-sanitizer.ts +0 -167
  45. package/src/app-server/klaw-owned-tool-runtime-contract.test.ts +0 -456
  46. package/src/app-server/local-runtime-attribution.ts +0 -39
  47. package/src/app-server/managed-binary.test.ts +0 -139
  48. package/src/app-server/managed-binary.ts +0 -193
  49. package/src/app-server/models.test.ts +0 -246
  50. package/src/app-server/models.ts +0 -172
  51. package/src/app-server/native-hook-relay.test.ts +0 -271
  52. package/src/app-server/native-hook-relay.ts +0 -150
  53. package/src/app-server/native-subagent-task-mirror.test.ts +0 -573
  54. package/src/app-server/native-subagent-task-mirror.ts +0 -497
  55. package/src/app-server/outcome-fallback-runtime-contract.test.ts +0 -404
  56. package/src/app-server/plugin-activation.test.ts +0 -336
  57. package/src/app-server/plugin-activation.ts +0 -283
  58. package/src/app-server/plugin-app-cache-key.ts +0 -74
  59. package/src/app-server/plugin-approval-roundtrip.ts +0 -122
  60. package/src/app-server/plugin-inventory.test.ts +0 -355
  61. package/src/app-server/plugin-inventory.ts +0 -357
  62. package/src/app-server/plugin-thread-config.test.ts +0 -865
  63. package/src/app-server/plugin-thread-config.ts +0 -455
  64. package/src/app-server/protocol-generated/json/DynamicToolCallParams.json +0 -33
  65. package/src/app-server/protocol-generated/json/v2/ErrorNotification.json +0 -199
  66. package/src/app-server/protocol-generated/json/v2/GetAccountResponse.json +0 -102
  67. package/src/app-server/protocol-generated/json/v2/ModelListResponse.json +0 -227
  68. package/src/app-server/protocol-generated/json/v2/ThreadResumeResponse.json +0 -2630
  69. package/src/app-server/protocol-generated/json/v2/ThreadStartResponse.json +0 -2630
  70. package/src/app-server/protocol-generated/json/v2/TurnCompletedNotification.json +0 -1659
  71. package/src/app-server/protocol-generated/json/v2/TurnStartResponse.json +0 -1655
  72. package/src/app-server/protocol-validators.test.ts +0 -75
  73. package/src/app-server/protocol-validators.ts +0 -203
  74. package/src/app-server/protocol.ts +0 -520
  75. package/src/app-server/rate-limit-cache.ts +0 -48
  76. package/src/app-server/rate-limits.test.ts +0 -202
  77. package/src/app-server/rate-limits.ts +0 -583
  78. package/src/app-server/request.ts +0 -73
  79. package/src/app-server/run-attempt.context-engine.test.ts +0 -1004
  80. package/src/app-server/run-attempt.test.ts +0 -9477
  81. package/src/app-server/run-attempt.ts +0 -4683
  82. package/src/app-server/run-attempt.vision-tools.test.ts +0 -35
  83. package/src/app-server/schema-normalization-runtime-contract.test.ts +0 -206
  84. package/src/app-server/session-binding.test.ts +0 -303
  85. package/src/app-server/session-binding.ts +0 -398
  86. package/src/app-server/session-history.ts +0 -44
  87. package/src/app-server/shared-client.test.ts +0 -589
  88. package/src/app-server/shared-client.ts +0 -289
  89. package/src/app-server/side-question.test.ts +0 -1175
  90. package/src/app-server/side-question.ts +0 -1007
  91. package/src/app-server/test-support.ts +0 -48
  92. package/src/app-server/thread-lifecycle.test.ts +0 -447
  93. package/src/app-server/thread-lifecycle.ts +0 -939
  94. package/src/app-server/thread-lifecycle.user-mcp-servers.test.ts +0 -442
  95. package/src/app-server/timeout.ts +0 -9
  96. package/src/app-server/tool-progress-normalization.ts +0 -77
  97. package/src/app-server/trajectory.test.ts +0 -205
  98. package/src/app-server/trajectory.ts +0 -365
  99. package/src/app-server/transcript-mirror.test.ts +0 -524
  100. package/src/app-server/transcript-mirror.ts +0 -208
  101. package/src/app-server/transcript-repair-runtime-contract.test.ts +0 -44
  102. package/src/app-server/transport-stdio.test.ts +0 -171
  103. package/src/app-server/transport-stdio.ts +0 -107
  104. package/src/app-server/transport-websocket.test.ts +0 -69
  105. package/src/app-server/transport-websocket.ts +0 -90
  106. package/src/app-server/transport.ts +0 -117
  107. package/src/app-server/user-input-bridge.test.ts +0 -249
  108. package/src/app-server/user-input-bridge.ts +0 -316
  109. package/src/app-server/version.ts +0 -4
  110. package/src/app-server/vision-tools.ts +0 -12
  111. package/src/command-account.ts +0 -544
  112. package/src/command-formatters.ts +0 -425
  113. package/src/command-handlers.ts +0 -2004
  114. package/src/command-rpc.test.ts +0 -16
  115. package/src/command-rpc.ts +0 -142
  116. package/src/commands.test.ts +0 -3312
  117. package/src/commands.ts +0 -65
  118. package/src/conversation-binding-data.ts +0 -124
  119. package/src/conversation-binding.test.ts +0 -599
  120. package/src/conversation-binding.ts +0 -561
  121. package/src/conversation-control.test.ts +0 -126
  122. package/src/conversation-control.ts +0 -303
  123. package/src/conversation-turn-collector.test.ts +0 -191
  124. package/src/conversation-turn-collector.ts +0 -186
  125. package/src/conversation-turn-input.test.ts +0 -141
  126. package/src/conversation-turn-input.ts +0 -106
  127. package/src/manifest.test.ts +0 -20
  128. package/src/migration/apply.ts +0 -501
  129. package/src/migration/helpers.ts +0 -55
  130. package/src/migration/plan.ts +0 -461
  131. package/src/migration/provider.test.ts +0 -1741
  132. package/src/migration/provider.ts +0 -41
  133. package/src/migration/source.ts +0 -643
  134. package/src/migration/targets.ts +0 -25
  135. package/src/node-cli-sessions.test.ts +0 -180
  136. package/src/node-cli-sessions.ts +0 -711
  137. package/test-api.ts +0 -82
  138. package/tsconfig.json +0 -16
@@ -1,683 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { describeControlFailure } from "./capabilities.js";
3
- import type { CodexAppServerClient } from "./client.js";
4
- import {
5
- resolveCodexAppServerRuntimeOptions,
6
- resolveCodexComputerUseConfig,
7
- type CodexComputerUseConfig,
8
- type ResolvedCodexComputerUseConfig,
9
- } from "./config.js";
10
- import type {
11
- CodexListMcpServerStatusResponse,
12
- CodexMcpServerStatus,
13
- CodexPluginDetail,
14
- CodexPluginListResponse,
15
- CodexPluginReadResponse,
16
- CodexRequestObject,
17
- JsonValue,
18
- } from "./protocol.js";
19
- import { requestCodexAppServerJson } from "./request.js";
20
-
21
- export type CodexComputerUseRequest = <T = JsonValue | undefined>(
22
- method: string,
23
- params?: unknown,
24
- ) => Promise<T>;
25
-
26
- type CodexComputerUseStatusReason =
27
- | "disabled"
28
- | "marketplace_missing"
29
- | "plugin_not_installed"
30
- | "plugin_disabled"
31
- | "remote_install_unsupported"
32
- | "mcp_missing"
33
- | "ready"
34
- | "check_failed"
35
- | "auto_install_blocked";
36
-
37
- export type CodexComputerUseStatus = {
38
- enabled: boolean;
39
- ready: boolean;
40
- reason: CodexComputerUseStatusReason;
41
- installed: boolean;
42
- pluginEnabled: boolean;
43
- mcpServerAvailable: boolean;
44
- pluginName: string;
45
- mcpServerName: string;
46
- marketplaceName?: string;
47
- marketplacePath?: string;
48
- tools: string[];
49
- message: string;
50
- };
51
-
52
- class CodexComputerUseSetupError extends Error {
53
- readonly status: CodexComputerUseStatus;
54
-
55
- constructor(status: CodexComputerUseStatus) {
56
- super(status.message);
57
- this.name = "CodexComputerUseSetupError";
58
- this.status = status;
59
- }
60
- }
61
-
62
- export type CodexComputerUseSetupParams = {
63
- pluginConfig?: unknown;
64
- overrides?: Partial<CodexComputerUseConfig>;
65
- request?: CodexComputerUseRequest;
66
- client?: CodexAppServerClient;
67
- timeoutMs?: number;
68
- signal?: AbortSignal;
69
- forceEnable?: boolean;
70
- defaultBundledMarketplacePath?: string;
71
- };
72
-
73
- type MarketplaceRef =
74
- | {
75
- kind: "local";
76
- name?: string;
77
- path: string;
78
- }
79
- | {
80
- kind: "remote";
81
- name: string;
82
- remoteMarketplaceName: string;
83
- };
84
-
85
- type MarketplaceResolution = {
86
- marketplace?: MarketplaceRef;
87
- message?: string;
88
- };
89
-
90
- type PluginInspection =
91
- | {
92
- ok: true;
93
- plugin: CodexPluginDetail;
94
- }
95
- | {
96
- ok: false;
97
- status: CodexComputerUseStatus;
98
- };
99
-
100
- const CURATED_MARKETPLACE_POLL_INTERVAL_MS = 2_000;
101
- const COMPUTER_USE_MARKETPLACE_NAME_PRIORITY = ["openai-bundled", "openai-curated", "local"];
102
- const DEFAULT_CODEX_BUNDLED_MARKETPLACE_PATH =
103
- "/Applications/Codex.app/Contents/Resources/plugins/openai-bundled";
104
-
105
- export async function readCodexComputerUseStatus(
106
- params: CodexComputerUseSetupParams = {},
107
- ): Promise<CodexComputerUseStatus> {
108
- const config = resolveComputerUseConfig(params);
109
- if (!config.enabled) {
110
- return disabledStatus(config);
111
- }
112
- try {
113
- return await inspectCodexComputerUse({
114
- ...params,
115
- config,
116
- installPlugin: false,
117
- });
118
- } catch (error) {
119
- return unavailableStatus(
120
- config,
121
- "check_failed",
122
- `Computer Use check failed: ${describeControlFailure(error)}`,
123
- );
124
- }
125
- }
126
-
127
- export async function ensureCodexComputerUse(
128
- params: CodexComputerUseSetupParams = {},
129
- ): Promise<CodexComputerUseStatus> {
130
- const config = resolveComputerUseConfig(params);
131
- if (!config.enabled) {
132
- return disabledStatus(config);
133
- }
134
- const status = await inspectCodexComputerUse({
135
- ...params,
136
- config,
137
- installPlugin: false,
138
- });
139
- if (status.ready) {
140
- return status;
141
- }
142
- if (config.autoInstall) {
143
- const blockedAutoInstallStatus = blockUnsafeAutoInstallStatus(config);
144
- if (blockedAutoInstallStatus) {
145
- throw new CodexComputerUseSetupError(blockedAutoInstallStatus);
146
- }
147
- const installedStatus = await inspectCodexComputerUse({
148
- ...params,
149
- config,
150
- installPlugin: true,
151
- });
152
- if (!installedStatus.ready) {
153
- throw new CodexComputerUseSetupError(installedStatus);
154
- }
155
- return installedStatus;
156
- }
157
- if (!status.ready) {
158
- throw new CodexComputerUseSetupError(status);
159
- }
160
- return status;
161
- }
162
-
163
- export async function installCodexComputerUse(
164
- params: CodexComputerUseSetupParams = {},
165
- ): Promise<CodexComputerUseStatus> {
166
- const config = resolveComputerUseConfig({
167
- ...params,
168
- forceEnable: true,
169
- overrides: { ...params.overrides, enabled: true, autoInstall: true },
170
- });
171
- const status = await inspectCodexComputerUse({
172
- ...params,
173
- config,
174
- installPlugin: true,
175
- });
176
- if (!status.ready) {
177
- throw new CodexComputerUseSetupError(status);
178
- }
179
- return status;
180
- }
181
-
182
- async function inspectCodexComputerUse(params: {
183
- pluginConfig?: unknown;
184
- request?: CodexComputerUseRequest;
185
- client?: CodexAppServerClient;
186
- timeoutMs?: number;
187
- signal?: AbortSignal;
188
- config: ResolvedCodexComputerUseConfig;
189
- installPlugin: boolean;
190
- defaultBundledMarketplacePath?: string;
191
- }): Promise<CodexComputerUseStatus> {
192
- const request = createComputerUseRequest(params);
193
- if (params.installPlugin) {
194
- await request<JsonValue>("experimentalFeature/enablement/set", {
195
- enablement: { plugins: true },
196
- } satisfies CodexRequestObject);
197
- }
198
-
199
- const marketplace = await resolveMarketplaceRef({
200
- request,
201
- config: params.config,
202
- allowAdd: params.installPlugin,
203
- signal: params.signal,
204
- defaultBundledMarketplacePath: params.defaultBundledMarketplacePath,
205
- });
206
- if (!marketplace.marketplace) {
207
- return unavailableStatus(
208
- params.config,
209
- "marketplace_missing",
210
- marketplace.message ??
211
- `No Codex marketplace containing ${params.config.pluginName} is registered. Configure computerUse.marketplaceSource or computerUse.marketplacePath, then run /codex computer-use install.`,
212
- );
213
- }
214
-
215
- const pluginInspection = await ensureComputerUsePlugin({
216
- request,
217
- config: params.config,
218
- marketplace: marketplace.marketplace,
219
- installPlugin: params.installPlugin,
220
- });
221
- if (!pluginInspection.ok) {
222
- return pluginInspection.status;
223
- }
224
-
225
- return await readComputerUseTools({
226
- request,
227
- config: params.config,
228
- plugin: pluginInspection.plugin,
229
- installPlugin: params.installPlugin,
230
- });
231
- }
232
-
233
- async function ensureComputerUsePlugin(params: {
234
- request: CodexComputerUseRequest;
235
- config: ResolvedCodexComputerUseConfig;
236
- marketplace: MarketplaceRef;
237
- installPlugin: boolean;
238
- }): Promise<PluginInspection> {
239
- let plugin = await readComputerUsePlugin(
240
- params.request,
241
- params.marketplace,
242
- params.config.pluginName,
243
- );
244
- if (!plugin.summary.installed || !plugin.summary.enabled) {
245
- if (!params.installPlugin) {
246
- return {
247
- ok: false,
248
- status: statusFromPlugin({
249
- config: params.config,
250
- plugin,
251
- tools: [],
252
- reason: pluginSetupReason(plugin, params.marketplace),
253
- message: pluginSetupMessage(params.config, plugin, params.marketplace),
254
- }),
255
- };
256
- }
257
- if (params.marketplace.kind === "remote") {
258
- return {
259
- ok: false,
260
- status: statusFromPlugin({
261
- config: params.config,
262
- plugin,
263
- tools: [],
264
- reason: "remote_install_unsupported",
265
- message: remoteInstallUnsupportedMessage(plugin, params.marketplace),
266
- }),
267
- };
268
- }
269
- await params.request<JsonValue>(
270
- "plugin/install",
271
- pluginRequestParams(params.marketplace, params.config.pluginName),
272
- );
273
- await reloadMcpServers(params.request);
274
- plugin = await readComputerUsePlugin(
275
- params.request,
276
- params.marketplace,
277
- params.config.pluginName,
278
- );
279
- }
280
- if (!plugin.summary.installed || !plugin.summary.enabled) {
281
- return {
282
- ok: false,
283
- status: statusFromPlugin({
284
- config: params.config,
285
- plugin,
286
- tools: [],
287
- reason: pluginSetupReason(plugin, params.marketplace),
288
- message: pluginSetupMessage(params.config, plugin, params.marketplace),
289
- }),
290
- };
291
- }
292
- return { ok: true, plugin };
293
- }
294
-
295
- async function readComputerUseTools(params: {
296
- request: CodexComputerUseRequest;
297
- config: ResolvedCodexComputerUseConfig;
298
- plugin: CodexPluginDetail;
299
- installPlugin: boolean;
300
- }): Promise<CodexComputerUseStatus> {
301
- let server = await readMcpServerStatus(params.request, params.config.mcpServerName);
302
- if (!server && params.installPlugin) {
303
- await reloadMcpServers(params.request);
304
- server = await readMcpServerStatus(params.request, params.config.mcpServerName);
305
- }
306
- if (!server) {
307
- return statusFromPlugin({
308
- config: params.config,
309
- plugin: params.plugin,
310
- tools: [],
311
- reason: "mcp_missing",
312
- message: `Computer Use is installed, but the ${params.config.mcpServerName} MCP server is not available.`,
313
- });
314
- }
315
-
316
- return statusFromPlugin({
317
- config: params.config,
318
- plugin: params.plugin,
319
- tools: Object.keys(server.tools).toSorted(),
320
- reason: "ready",
321
- message: "Computer Use is ready.",
322
- });
323
- }
324
-
325
- async function resolveMarketplaceRef(params: {
326
- request: CodexComputerUseRequest;
327
- config: ResolvedCodexComputerUseConfig;
328
- allowAdd: boolean;
329
- signal?: AbortSignal;
330
- defaultBundledMarketplacePath?: string;
331
- }): Promise<MarketplaceResolution> {
332
- let preferredMarketplaceName = params.config.marketplaceName;
333
- if (params.config.marketplaceSource && params.allowAdd) {
334
- const added = await params.request<{ marketplaceName?: string }>("marketplace/add", {
335
- source: params.config.marketplaceSource,
336
- } satisfies CodexRequestObject);
337
- preferredMarketplaceName ??= added.marketplaceName;
338
- }
339
-
340
- if (params.config.marketplacePath) {
341
- const marketplace: MarketplaceRef = preferredMarketplaceName
342
- ? { kind: "local", name: preferredMarketplaceName, path: params.config.marketplacePath }
343
- : { kind: "local", path: params.config.marketplacePath };
344
- return { marketplace };
345
- }
346
-
347
- let candidates = await listComputerUseMarketplaceCandidates(params.request, params.config);
348
- if (candidates.length === 0 && shouldAddBundledComputerUseMarketplace(params)) {
349
- const bundledMarketplacePath =
350
- params.defaultBundledMarketplacePath ?? DEFAULT_CODEX_BUNDLED_MARKETPLACE_PATH;
351
- const added = await params.request<{ marketplaceName?: string }>("marketplace/add", {
352
- source: bundledMarketplacePath,
353
- } satisfies CodexRequestObject);
354
- preferredMarketplaceName ??= added.marketplaceName;
355
- candidates = await listComputerUseMarketplaceCandidates(params.request, params.config);
356
- }
357
-
358
- const waitUntil = marketplaceDiscoveryWaitUntil(params);
359
- while (candidates.length === 0) {
360
- if (Date.now() >= waitUntil) {
361
- break;
362
- }
363
- await delay(
364
- Math.min(CURATED_MARKETPLACE_POLL_INTERVAL_MS, waitUntil - Date.now()),
365
- params.signal,
366
- );
367
- candidates = await listComputerUseMarketplaceCandidates(params.request, params.config);
368
- }
369
-
370
- if (preferredMarketplaceName) {
371
- const preferred = candidates.find((candidate) => candidate.name === preferredMarketplaceName);
372
- if (preferred) {
373
- return { marketplace: preferred };
374
- }
375
- return {
376
- 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.`,
377
- };
378
- }
379
- if (candidates.length > 1) {
380
- const preferred = chooseKnownComputerUseMarketplace(candidates);
381
- if (preferred) {
382
- return { marketplace: preferred };
383
- }
384
- return {
385
- message: `Multiple Codex marketplaces contain ${params.config.pluginName}. Configure computerUse.marketplaceName or computerUse.marketplacePath to choose one.`,
386
- };
387
- }
388
- if (params.config.marketplaceSource && !params.allowAdd && candidates.length === 0) {
389
- return {
390
- message:
391
- "Computer Use marketplace source is configured but has not been registered. Run /codex computer-use install to register it.",
392
- };
393
- }
394
- const marketplace = candidates[0];
395
- return marketplace ? { marketplace } : {};
396
- }
397
-
398
- async function listComputerUseMarketplaceCandidates(
399
- request: CodexComputerUseRequest,
400
- config: ResolvedCodexComputerUseConfig,
401
- ): Promise<MarketplaceRef[]> {
402
- const listed = await request<CodexPluginListResponse>("plugin/list", {
403
- cwds: [],
404
- } satisfies CodexRequestObject);
405
- return findComputerUseMarketplaces(listed, config.pluginName);
406
- }
407
-
408
- function blockUnsafeAutoInstallStatus(
409
- config: ResolvedCodexComputerUseConfig,
410
- ): CodexComputerUseStatus | undefined {
411
- if (!config.marketplaceSource) {
412
- return undefined;
413
- }
414
- return unavailableStatus(
415
- config,
416
- "auto_install_blocked",
417
- "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.",
418
- );
419
- }
420
-
421
- function shouldAddBundledComputerUseMarketplace(params: {
422
- config: ResolvedCodexComputerUseConfig;
423
- allowAdd: boolean;
424
- defaultBundledMarketplacePath?: string;
425
- }): boolean {
426
- const bundledMarketplacePath =
427
- params.defaultBundledMarketplacePath ?? DEFAULT_CODEX_BUNDLED_MARKETPLACE_PATH;
428
- return (
429
- params.allowAdd &&
430
- !params.config.marketplaceSource &&
431
- !params.config.marketplacePath &&
432
- !params.config.marketplaceName &&
433
- existsSync(bundledMarketplacePath)
434
- );
435
- }
436
-
437
- function findComputerUseMarketplaces(
438
- listed: CodexPluginListResponse,
439
- pluginName: string,
440
- ): MarketplaceRef[] {
441
- return listed.marketplaces
442
- .filter((marketplace) =>
443
- marketplace.plugins.some(
444
- (plugin) =>
445
- plugin.name === pluginName ||
446
- plugin.id === pluginName ||
447
- plugin.id === `${pluginName}@${marketplace.name}`,
448
- ),
449
- )
450
- .map((marketplace) => {
451
- if (marketplace.path) {
452
- return { kind: "local", name: marketplace.name, path: marketplace.path };
453
- }
454
- return { kind: "remote", name: marketplace.name, remoteMarketplaceName: marketplace.name };
455
- });
456
- }
457
-
458
- function chooseKnownComputerUseMarketplace(
459
- candidates: MarketplaceRef[],
460
- ): MarketplaceRef | undefined {
461
- for (const marketplaceName of COMPUTER_USE_MARKETPLACE_NAME_PRIORITY) {
462
- const candidate = candidates.find((marketplace) => marketplace.name === marketplaceName);
463
- if (candidate) {
464
- return candidate;
465
- }
466
- }
467
- return undefined;
468
- }
469
-
470
- function marketplaceDiscoveryWaitUntil(params: {
471
- config: ResolvedCodexComputerUseConfig;
472
- allowAdd: boolean;
473
- }): number {
474
- if (
475
- params.allowAdd &&
476
- !params.config.marketplaceSource &&
477
- !params.config.marketplacePath &&
478
- !params.config.marketplaceName
479
- ) {
480
- return Date.now() + params.config.marketplaceDiscoveryTimeoutMs;
481
- }
482
- return 0;
483
- }
484
-
485
- async function delay(ms: number, signal?: AbortSignal): Promise<void> {
486
- if (signal?.aborted) {
487
- throw abortError(signal);
488
- }
489
- await new Promise<void>((resolve, reject) => {
490
- let timer: ReturnType<typeof setTimeout>;
491
- const onAbort = () => {
492
- clearTimeout(timer);
493
- signal?.removeEventListener("abort", onAbort);
494
- reject(abortError(signal));
495
- };
496
- timer = setTimeout(() => {
497
- signal?.removeEventListener("abort", onAbort);
498
- resolve();
499
- }, ms);
500
- signal?.addEventListener("abort", onAbort, { once: true });
501
- });
502
- }
503
-
504
- function abortError(signal?: AbortSignal): Error {
505
- const reason = signal?.reason;
506
- return reason instanceof Error ? reason : new Error("Computer Use setup was aborted.");
507
- }
508
-
509
- async function readComputerUsePlugin(
510
- request: CodexComputerUseRequest,
511
- marketplace: MarketplaceRef,
512
- pluginName: string,
513
- ): Promise<CodexPluginDetail> {
514
- const response = await request<CodexPluginReadResponse>(
515
- "plugin/read",
516
- pluginRequestParams(marketplace, pluginName),
517
- );
518
- return response.plugin;
519
- }
520
-
521
- async function readMcpServerStatus(
522
- request: CodexComputerUseRequest,
523
- serverName: string,
524
- ): Promise<CodexMcpServerStatus | undefined> {
525
- let cursor: string | null | undefined;
526
- do {
527
- const response = await request<CodexListMcpServerStatusResponse>("mcpServerStatus/list", {
528
- cursor,
529
- limit: 100,
530
- detail: "toolsAndAuthOnly",
531
- } satisfies CodexRequestObject);
532
- const found = response.data.find((server) => server.name === serverName);
533
- if (found) {
534
- return found;
535
- }
536
- cursor = response.nextCursor;
537
- } while (cursor);
538
- return undefined;
539
- }
540
-
541
- async function reloadMcpServers(request: CodexComputerUseRequest): Promise<void> {
542
- await request("config/mcpServer/reload", undefined);
543
- }
544
-
545
- function pluginRequestParams(marketplace: MarketplaceRef, pluginName: string) {
546
- return {
547
- ...(marketplace.kind === "local" ? { marketplacePath: marketplace.path } : {}),
548
- ...(marketplace.kind === "remote"
549
- ? { remoteMarketplaceName: marketplace.remoteMarketplaceName }
550
- : {}),
551
- pluginName,
552
- };
553
- }
554
-
555
- function pluginSetupReason(
556
- plugin: CodexPluginDetail,
557
- marketplace: MarketplaceRef,
558
- ): CodexComputerUseStatusReason {
559
- if (marketplace.kind === "remote") {
560
- return "remote_install_unsupported";
561
- }
562
- return plugin.summary.installed ? "plugin_disabled" : "plugin_not_installed";
563
- }
564
-
565
- function pluginSetupMessage(
566
- config: ResolvedCodexComputerUseConfig,
567
- plugin: CodexPluginDetail,
568
- marketplace: MarketplaceRef,
569
- ): string {
570
- if (marketplace.kind === "remote") {
571
- return remoteInstallUnsupportedMessage(plugin, marketplace);
572
- }
573
- if (!plugin.summary.installed) {
574
- return "Computer Use is available but not installed. Run /codex computer-use install or enable computerUse.autoInstall.";
575
- }
576
- 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.`;
577
- }
578
-
579
- function remoteInstallUnsupportedMessage(
580
- plugin: CodexPluginDetail,
581
- marketplace: MarketplaceRef,
582
- ): string {
583
- const marketplaceName = marketplace.name ?? plugin.marketplaceName;
584
- const state = plugin.summary.installed ? "installed but disabled" : "available";
585
- return `Computer Use is ${state} 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.`;
586
- }
587
-
588
- function statusFromPlugin(params: {
589
- config: ResolvedCodexComputerUseConfig;
590
- plugin: CodexPluginDetail;
591
- tools: string[];
592
- reason: CodexComputerUseStatusReason;
593
- message: string;
594
- }): CodexComputerUseStatus {
595
- return {
596
- enabled: true,
597
- ready:
598
- params.plugin.summary.installed && params.plugin.summary.enabled && params.tools.length > 0,
599
- reason: params.reason,
600
- installed: params.plugin.summary.installed,
601
- pluginEnabled: params.plugin.summary.enabled,
602
- mcpServerAvailable: params.tools.length > 0,
603
- pluginName: params.config.pluginName,
604
- mcpServerName: params.config.mcpServerName,
605
- marketplaceName: params.plugin.marketplaceName,
606
- ...(params.plugin.marketplacePath ? { marketplacePath: params.plugin.marketplacePath } : {}),
607
- tools: params.tools,
608
- message: params.message,
609
- };
610
- }
611
-
612
- function disabledStatus(config: ResolvedCodexComputerUseConfig): CodexComputerUseStatus {
613
- return {
614
- enabled: false,
615
- ready: false,
616
- reason: "disabled",
617
- installed: false,
618
- pluginEnabled: false,
619
- mcpServerAvailable: false,
620
- pluginName: config.pluginName,
621
- mcpServerName: config.mcpServerName,
622
- tools: [],
623
- message: "Computer Use is disabled.",
624
- };
625
- }
626
-
627
- function unavailableStatus(
628
- config: ResolvedCodexComputerUseConfig,
629
- reason: CodexComputerUseStatusReason,
630
- message: string,
631
- ): CodexComputerUseStatus {
632
- return {
633
- enabled: true,
634
- ready: false,
635
- reason,
636
- installed: false,
637
- pluginEnabled: false,
638
- mcpServerAvailable: false,
639
- pluginName: config.pluginName,
640
- mcpServerName: config.mcpServerName,
641
- ...(config.marketplaceName ? { marketplaceName: config.marketplaceName } : {}),
642
- ...(config.marketplacePath ? { marketplacePath: config.marketplacePath } : {}),
643
- tools: [],
644
- message,
645
- };
646
- }
647
-
648
- function createComputerUseRequest(params: {
649
- pluginConfig?: unknown;
650
- request?: CodexComputerUseRequest;
651
- client?: CodexAppServerClient;
652
- timeoutMs?: number;
653
- signal?: AbortSignal;
654
- }): CodexComputerUseRequest {
655
- if (params.request) {
656
- return params.request;
657
- }
658
- if (params.client) {
659
- return async <T = JsonValue | undefined>(method: string, requestParams?: unknown) =>
660
- await params.client!.request<T>(method, requestParams, {
661
- timeoutMs: params.timeoutMs,
662
- signal: params.signal,
663
- });
664
- }
665
- const runtime = resolveCodexAppServerRuntimeOptions({ pluginConfig: params.pluginConfig });
666
- return async <T = JsonValue | undefined>(method: string, requestParams?: unknown) =>
667
- await requestCodexAppServerJson<T>({
668
- method,
669
- requestParams,
670
- timeoutMs: params.timeoutMs ?? runtime.requestTimeoutMs,
671
- startOptions: runtime.start,
672
- });
673
- }
674
-
675
- function resolveComputerUseConfig(
676
- params: Pick<CodexComputerUseSetupParams, "pluginConfig" | "overrides" | "forceEnable">,
677
- ): ResolvedCodexComputerUseConfig {
678
- const overrides = params.forceEnable ? { ...params.overrides, enabled: true } : params.overrides;
679
- return resolveCodexComputerUseConfig({
680
- pluginConfig: params.pluginConfig,
681
- overrides,
682
- });
683
- }