INNER CODE UNIT · TypeScript

gracefulExitOnInitFailure

AmrDab/clawdcursor · src/surface/cli.ts:109

function gracefulExitOnInitFailure(code: number, agent: { disconnect: () => unknown }): void {
  process.exitCode = code;
  releasePidFile('start');
  try { agent.disconnect(); } catch { /* non-fatal */ }
  // Hard-kill safety net: if the loop hangs, force-exit after 2s.
  // .unref() so the timer itself doesn't keep the loop alive.
  setTimeout(() => process.exit(code), 2000).unref();
}

const program = new Command();

async function isClawdInstance(port: number): Promise<boolean> {
  try {
    const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(2000) });
    const data = await res.json() as any;
    return data.status === 'ok' && typeof data.version === 'string';
  } catch {
    return false;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…