(input: {
readonly elicitationMode: "browser" | "model";
readonly artifacts: boolean;
})
| 1469 | }; |
| 1470 | |
| 1471 | const runStdioMcpSession = (input: { |
| 1472 | readonly elicitationMode: "browser" | "model"; |
| 1473 | readonly artifacts: boolean; |
| 1474 | }) => |
| 1475 | Effect.gen(function* () { |
| 1476 | // `executor mcp` never owns the local database. If a local server is already |
| 1477 | // running, bridge this stdio client to it; otherwise ensure a durable |
| 1478 | // background daemon is up and bridge to that. ensureDaemon is the race-safe |
| 1479 | // election: concurrent cold starts elect one owner and the losers wait for |
| 1480 | // its manifest (waitForDaemonStartupTarget) rather than failing. Bridging |
| 1481 | // means many MCP clients, the web UI, and the desktop app share one owner, |
| 1482 | // and that owner's lifetime is never tied to a transient MCP client. |
| 1483 | const active = yield* readActiveLocalServerManifest(); |
| 1484 | if (active) { |
| 1485 | yield* Effect.promise(() => |
| 1486 | runMcpHttpBridge({ |
| 1487 | manifest: active, |
| 1488 | elicitationMode: input.elicitationMode, |
| 1489 | artifacts: input.artifacts, |
| 1490 | }), |
| 1491 | ); |
| 1492 | return; |
| 1493 | } |
| 1494 | |
| 1495 | // No reachable owner yet: ensure one. If we lose the election (another |
| 1496 | // process became owner first), ensureDaemon may fail, but the winner's |
| 1497 | // manifest is then reachable, so re-read it and bridge to that instead. |
| 1498 | const elected = yield* ensureDaemon(DEFAULT_BASE_URL).pipe( |
| 1499 | Effect.flatMap(() => readActiveLocalServerManifest()), |
| 1500 | Effect.catch((error) => |
| 1501 | readActiveLocalServerManifest().pipe( |
| 1502 | Effect.flatMap((manifest) => (manifest ? Effect.succeed(manifest) : Effect.fail(error))), |
| 1503 | ), |
| 1504 | ), |
| 1505 | ); |
| 1506 | if (!elected) { |
| 1507 | return yield* Effect.fail( |
| 1508 | new Error("The local Executor daemon started but did not advertise a reachable manifest."), |
| 1509 | ); |
| 1510 | } |
| 1511 | yield* Effect.promise(() => |
| 1512 | runMcpHttpBridge({ |
| 1513 | manifest: elected, |
| 1514 | elicitationMode: input.elicitationMode, |
| 1515 | artifacts: input.artifacts, |
| 1516 | }), |
| 1517 | ); |
| 1518 | }); |
| 1519 | |
| 1520 | const scope = Options.string("scope").pipe( |
| 1521 | Options.optional, |
no test coverage detected