(input: {
port: number;
hostname: string;
allowedHosts: ReadonlyArray<string>;
authToken: string | undefined;
})
| 1085 | // --------------------------------------------------------------------------- |
| 1086 | |
| 1087 | const runForegroundSession = (input: { |
| 1088 | port: number; |
| 1089 | hostname: string; |
| 1090 | allowedHosts: ReadonlyArray<string>; |
| 1091 | authToken: string | undefined; |
| 1092 | }) => |
| 1093 | Effect.gen(function* () { |
| 1094 | const displayHost = |
| 1095 | input.hostname === "0.0.0.0" || input.hostname === "::" ? "localhost" : input.hostname; |
| 1096 | const restoreWebBaseUrl = installDefaultExecutorWebBaseUrl( |
| 1097 | `http://${displayHost}:${input.port}`, |
| 1098 | ); |
| 1099 | |
| 1100 | try { |
| 1101 | // No process-level startup lock: the DB ownership lock acquired inside |
| 1102 | // startServer (openOwnedLocalDatabase) is the real gate. server.json is |
| 1103 | // only an attach hint, and assertNoOtherActiveLocalServer is a friendly |
| 1104 | // fast-path that may race without being unsafe. |
| 1105 | yield* assertNoOtherActiveLocalServer(); |
| 1106 | const startResult = yield* startServerOrAttachOwnedDataDir({ |
| 1107 | port: input.port, |
| 1108 | hostname: input.hostname, |
| 1109 | allowedHosts: input.allowedHosts, |
| 1110 | authToken: input.authToken, |
| 1111 | embeddedWebUI, |
| 1112 | }); |
| 1113 | if (startResult.kind === "attached") { |
| 1114 | console.log(`Executor is already running at ${startResult.manifest.connection.origin}.`); |
| 1115 | return; |
| 1116 | } |
| 1117 | const server = startResult.server; |
| 1118 | const baseUrl = `http://${displayHost}:${server.port}`; |
| 1119 | yield* publishLocalServerManifest({ |
| 1120 | kind: "foreground", |
| 1121 | connection: normalizeExecutorServerConnection({ |
| 1122 | kind: "http", |
| 1123 | origin: baseUrl, |
| 1124 | displayName: "CLI web", |
| 1125 | auth: { kind: "bearer", token: server.authToken }, |
| 1126 | }), |
| 1127 | }); |
| 1128 | |
| 1129 | try { |
| 1130 | console.log(`Executor is ready.`); |
| 1131 | console.log(`Open: ${baseUrl}/?_token=${server.authToken}`); |
| 1132 | console.log(`Web: ${baseUrl}`); |
| 1133 | console.log(`MCP: ${baseUrl}/mcp`); |
| 1134 | console.log(`OpenAPI: ${baseUrl}/api/docs`); |
| 1135 | if (input.hostname !== "127.0.0.1" && input.hostname !== "localhost") { |
| 1136 | console.log( |
| 1137 | `\n⚠ Listening on ${input.hostname}. Executor runs arbitrary commands — only expose on trusted networks.`, |
| 1138 | ); |
| 1139 | if (input.allowedHosts.length > 0) { |
| 1140 | console.log(` Extra CORS origins: ${input.allowedHosts.join(", ")}`); |
| 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | // Best-effort upgrade nudge. `checkForUpdate` never throws and bounds |
no test coverage detected