(input: {
readonly elicitationMode: "browser" | "model";
readonly artifacts: boolean;
readonly searchTools: boolean;
readonly toolMode: "codemode" | "passthrough";
})
| 1486 | }; |
| 1487 | |
| 1488 | const runStdioMcpSession = (input: { |
| 1489 | readonly elicitationMode: "browser" | "model"; |
| 1490 | readonly artifacts: boolean; |
| 1491 | readonly searchTools: boolean; |
| 1492 | readonly toolMode: "codemode" | "passthrough"; |
| 1493 | }) => |
| 1494 | Effect.gen(function* () { |
| 1495 | // `executor mcp` never owns the local database. If a local server is already |
| 1496 | // running, bridge this stdio client to it; otherwise ensure a durable |
| 1497 | // background daemon is up and bridge to that. ensureDaemon is the race-safe |
| 1498 | // election: concurrent cold starts elect one owner and the losers wait for |
| 1499 | // its manifest (waitForDaemonStartupTarget) rather than failing. Bridging |
| 1500 | // means many MCP clients, the web UI, and the desktop app share one owner, |
| 1501 | // and that owner's lifetime is never tied to a transient MCP client. |
| 1502 | const active = yield* readActiveLocalServerManifest(); |
| 1503 | if (active) { |
| 1504 | yield* Effect.promise(() => |
| 1505 | runMcpHttpBridge({ |
| 1506 | manifest: active, |
| 1507 | elicitationMode: input.elicitationMode, |
| 1508 | artifacts: input.artifacts, |
| 1509 | searchTools: input.searchTools, |
| 1510 | toolMode: input.toolMode, |
| 1511 | }), |
| 1512 | ); |
| 1513 | return; |
| 1514 | } |
| 1515 | |
| 1516 | // No reachable owner yet: ensure one. If we lose the election (another |
| 1517 | // process became owner first), ensureDaemon may fail, but the winner's |
| 1518 | // manifest is then reachable, so re-read it and bridge to that instead. |
| 1519 | const elected = yield* ensureDaemon(DEFAULT_BASE_URL).pipe( |
| 1520 | Effect.flatMap(() => readActiveLocalServerManifest()), |
| 1521 | Effect.catch((error) => |
| 1522 | readActiveLocalServerManifest().pipe( |
| 1523 | Effect.flatMap((manifest) => (manifest ? Effect.succeed(manifest) : Effect.fail(error))), |
| 1524 | ), |
| 1525 | ), |
| 1526 | ); |
| 1527 | if (!elected) { |
| 1528 | return yield* Effect.fail( |
| 1529 | new Error("The local Executor daemon started but did not advertise a reachable manifest."), |
| 1530 | ); |
| 1531 | } |
| 1532 | yield* Effect.promise(() => |
| 1533 | runMcpHttpBridge({ |
| 1534 | manifest: elected, |
| 1535 | elicitationMode: input.elicitationMode, |
| 1536 | artifacts: input.artifacts, |
| 1537 | searchTools: input.searchTools, |
| 1538 | toolMode: input.toolMode, |
| 1539 | }), |
| 1540 | ); |
| 1541 | }); |
| 1542 | |
| 1543 | const scope = Options.string("scope").pipe( |
| 1544 | Options.optional, |
no test coverage detected