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

Function attachToSupervisedDaemon

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

Source from the content-addressed store, hash-verified

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

Callers 3

waitForSupervisedAttachFunction · 0.90
armSupervisedMonitorFunction · 0.90

Calls 5

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

Tested by

no test coverage detected