(id: string)
| 1458 | * Safe to run on demand: every probe tool is a listing or a status |
| 1459 | * read. If macOS has not yet asked, this is what makes it ask. */ |
| 1460 | const checkCodexPluginAccess = (id: string) => |
| 1461 | Effect.gen(function* () { |
| 1462 | if (!allowStdio) return { status: "unsupported" as const }; |
| 1463 | const plugins = yield* listCodexPlugins(); |
| 1464 | const plugin = plugins.find((entry) => entry.id === id); |
| 1465 | if (plugin === undefined) return { status: "unknown" as const }; |
| 1466 | if (!plugin.available) return { status: "not-installed" as const }; |
| 1467 | |
| 1468 | const mod = yield* Effect.promise(() => import("./codex-plugin-presets")); |
| 1469 | const preset = mod.CURATED_CODEX_PLUGINS.find((entry) => entry.id === id); |
| 1470 | const probe = preset?.probeTool; |
| 1471 | if (probe === undefined) return { status: "nothing-to-check" as const }; |
| 1472 | |
| 1473 | const connector = createMcpConnector({ |
| 1474 | transport: "stdio", |
| 1475 | command: plugin.command, |
| 1476 | args: plugin.args, |
| 1477 | env: plugin.env === undefined ? undefined : { ...plugin.env }, |
| 1478 | ...(plugin.appServer === undefined ? {} : { appServer: plugin.appServer }), |
| 1479 | }); |
| 1480 | |
| 1481 | // A probe that hangs is a real outcome, not an edge case: an Apple |
| 1482 | // Event blocks for as long as macOS sits on the consent decision. |
| 1483 | // Under the SDK's 60s default the card shows "Checking…" for a full |
| 1484 | // minute and then misreports the hang as a failed start. |
| 1485 | let timedOut = false; |
| 1486 | return yield* Effect.gen(function* () { |
| 1487 | const connection = yield* connector; |
| 1488 | const result = yield* Effect.tryPromise({ |
| 1489 | try: () => |
| 1490 | connection.client.callTool( |
| 1491 | { name: probe.name, arguments: probe.args }, |
| 1492 | { timeout: PROBE_ANSWER_TIMEOUT_MS }, |
| 1493 | ), |
| 1494 | catch: (cause) => { |
| 1495 | timedOut = isMcpRequestTimeout(cause); |
| 1496 | return new McpConnectionError({ |
| 1497 | transport: "appserver", |
| 1498 | message: "The plugin did not answer.", |
| 1499 | }); |
| 1500 | }, |
| 1501 | }).pipe(Effect.ensuring(Effect.promise(() => connection.close()))); |
| 1502 | |
| 1503 | const text = (Array.isArray(result.content) ? result.content : []) |
| 1504 | .map((block) => (block as { readonly text?: unknown }).text) |
| 1505 | .filter((value): value is string => typeof value === "string") |
| 1506 | .join(" "); |
| 1507 | if (result.isError === true) { |
| 1508 | return { status: "blocked" as const, message: text }; |
| 1509 | } |
| 1510 | return { status: "ok" as const }; |
| 1511 | }).pipe( |
| 1512 | // Any failure to even reach the plugin is reported the same way a |
| 1513 | // refusal is: the user cares that it does not work and why, not |
| 1514 | // which layer said no. |
| 1515 | // Distinguish the two ways this can fail by TAG, not by reading a |
| 1516 | // message off an unknown: the plugin refused, or we never reached |
| 1517 | // it at all. |
nothing calls this directly
no test coverage detected