MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / attachToSupervisedDaemon

Function attachToSupervisedDaemon

apps/desktop/src/main/sidecar.ts:443–480  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

441 * is handled by the existing single-instance / ownership logic.
442 */
443export async function attachToSupervisedDaemon(): Promise<SidecarConnection | null> {
444 const dataDir = executorScopeDir();
445 const manifest = readManifest(dataDir);
446 const decision = await resolveSupervisedDaemonAttach(manifest, {
447 isReachable: isDaemonReachable,
448 isPidAlive,
449 });
450 if (decision.kind === "attach") {
451 const { manifest, authToken } = decision;
452 const origin = manifest.connection.origin;
453 const url = new URL(origin);
454 sidecarLog.info(`attaching to supervised daemon at ${origin} (pid ${manifest.pid})`);
455 return {
456 baseUrl: origin,
457 hostname: url.hostname,
458 port: Number.parseInt(url.port, 10) || (url.protocol === "https:" ? 443 : 80),
459 username: SERVER_SETTINGS_USERNAME,
460 authToken,
461 child: null,
462 supervisedDaemon: true,
463 ownerVersion: manifest.owner.version,
464 ownerClient: manifest.owner.client,
465 ownerExecutablePath: manifest.owner.executablePath,
466 };
467 }
468
469 if (decision.kind === "remove-stale-manifest") {
470 removeManifestIfOwnedBy(dataDir, decision.pid);
471 return null;
472 }
473
474 if (!manifest || manifest.kind !== "cli-daemon") return null;
475
476 sidecarLog.warn(
477 `supervised daemon at ${manifest.connection.origin} (pid ${manifest.pid}) did not answer the health probe; keeping its manifest because the process is still alive`,
478 );
479 return null;
480}
481
482export async function stopSidecar(child: ChildProcess): Promise<void> {
483 expectedExits.add(child);

Callers 3

waitForSupervisedAttachFunction · 0.90
armSupervisedMonitorFunction · 0.90

Calls 6

executorScopeDirFunction · 0.85
removeManifestIfOwnedByFunction · 0.85
warnMethod · 0.80
readManifestFunction · 0.70
infoMethod · 0.65

Tested by

no test coverage detected