import { getOpenCodeServerUrl } from './sidecar-server';

// The OpenCode server is owned by the officer-opencode sidecar, which starts `opencode serve` on a
// random port (cwd = DATA_PATH/opencode_server) and reports it to the API (getOpenCodeServerUrl).
// All OpenCode HTTP traffic routes to whatever port the sidecar last reported.

// `isServerHealthy` lived here and had no callers — removed 2026-08-10 with the rest of the dead
// serve-turn client. It polled `/api/health`, which is a real route and answers `{"healthy":true}`, so
// it worked; it simply had nothing asking. `/global/health` is the richer one (it also reports the
// version) if a health check is ever wanted back.

/** The base URL of the OpenCode server the sidecar is running. Throws if it hasn't reported in yet. */
export async function ensureServer(): Promise<{ baseUrl: string }> {
  const baseUrl = getOpenCodeServerUrl();
  if (!baseUrl) throw new Error('OpenCode sidecar server not available yet');
  return { baseUrl };
}
