()
| 406 | * is handled by the existing single-instance / ownership logic. |
| 407 | */ |
| 408 | export async function attachToSupervisedDaemon(): Promise<SidecarConnection | null> { |
| 409 | const dataDir = join(homedir(), ".executor"); |
| 410 | const manifest = readManifest(dataDir); |
| 411 | const decision = await resolveSupervisedDaemonAttach(manifest, { |
| 412 | isReachable: isDaemonReachable, |
| 413 | isPidAlive, |
| 414 | }); |
| 415 | if (decision.kind === "attach") { |
| 416 | const { manifest, authToken } = decision; |
| 417 | const origin = manifest.connection.origin; |
| 418 | const url = new URL(origin); |
| 419 | sidecarLog.info(`attaching to supervised daemon at ${origin} (pid ${manifest.pid})`); |
| 420 | return { |
| 421 | baseUrl: origin, |
| 422 | hostname: url.hostname, |
| 423 | port: Number.parseInt(url.port, 10) || (url.protocol === "https:" ? 443 : 80), |
| 424 | username: SERVER_SETTINGS_USERNAME, |
| 425 | authToken, |
| 426 | child: null, |
| 427 | supervisedDaemon: true, |
| 428 | ownerVersion: manifest.owner.version, |
| 429 | ownerClient: manifest.owner.client, |
| 430 | ownerExecutablePath: manifest.owner.executablePath, |
| 431 | }; |
| 432 | } |
| 433 | |
| 434 | if (decision.kind === "remove-stale-manifest") { |
| 435 | removeManifestIfOwnedBy(dataDir, decision.pid); |
| 436 | return null; |
| 437 | } |
| 438 | |
| 439 | if (!manifest || manifest.kind !== "cli-daemon") return null; |
| 440 | |
| 441 | sidecarLog.warn( |
| 442 | `supervised daemon at ${manifest.connection.origin} (pid ${manifest.pid}) did not answer the health probe; keeping its manifest because the process is still alive`, |
| 443 | ); |
| 444 | return null; |
| 445 | } |
| 446 | |
| 447 | export async function stopSidecar(child: ChildProcess): Promise<void> { |
| 448 | expectedExits.add(child); |
no test coverage detected