MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / exploreViaDaemon

Function exploreViaDaemon

src/mcp/hook-client.ts:210–232  ·  view source on GitHub ↗
(projectRoot: string, query: string, deadlineMs: number)

Source from the content-addressed store, hash-verified

208 * `deadlineMs` for the connection and the answer together. Never throws.
209 */
210export async function exploreViaDaemon(projectRoot: string, query: string, deadlineMs: number): Promise<DaemonExplore> {
211 if (daemonOptOutSet()) return UNAVAILABLE;
212 let socket: net.Socket | null = null;
213 let settled = false;
214 let timer: NodeJS.Timeout | undefined;
215 const asked = (async (): Promise<DaemonExplore> => {
216 socket = await connectToDaemon(projectRoot);
217 if (!socket) return UNAVAILABLE;
218 // The deadline passed while this was still connecting.
219 if (settled) { socket.destroy(); return UNAVAILABLE; }
220 return ask(socket, query);
221 })().catch(() => UNAVAILABLE);
222 const deadline = new Promise<DaemonExplore>((resolve) => {
223 timer = setTimeout(() => resolve({ status: 'timed-out' }), deadlineMs);
224 });
225 try {
226 return await Promise.race([asked, deadline]);
227 } finally {
228 settled = true;
229 clearTimeout(timer);
230 (socket as net.Socket | null)?.destroy();
231 }
232}

Callers 4

mainFunction · 0.85

Calls 5

daemonOptOutSetFunction · 0.90
connectToDaemonFunction · 0.85
askFunction · 0.70
resolveFunction · 0.50
destroyMethod · 0.45

Tested by

no test coverage detected