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

Function onData

src/mcp/proxy.ts:460–488  ·  view source on GitHub ↗
(chunk: string | Buffer)

Source from the content-addressed store, hash-verified

458 clearTimeout(timer);
459 };
460 const onData = (chunk: string | Buffer) => {
461 buffer += typeof chunk === 'string' ? chunk : chunk.toString('utf8');
462 const idx = buffer.indexOf('\n');
463 if (idx === -1) {
464 if (buffer.length > MAX_HELLO_LINE_BYTES) {
465 cleanup();
466 reject(new Error('daemon hello line exceeded size limit'));
467 }
468 return;
469 }
470 const line = buffer.slice(0, idx);
471 // Re-emit anything past the newline so the pipe-stage sees it.
472 const tail = buffer.slice(idx + 1);
473 cleanup();
474 if (tail.length > 0) {
475 // Push back via unshift — Node's net.Socket supports it on readable streams.
476 socket.unshift(tail);
477 }
478 try {
479 const parsed = JSON.parse(line) as DaemonHello;
480 if (typeof parsed.codegraph !== 'string' || typeof parsed.pid !== 'number') {
481 reject(new Error('daemon hello missing required fields'));
482 return;
483 }
484 resolve(parsed);
485 } catch (err) {
486 reject(new Error(`daemon hello not JSON: ${err instanceof Error ? err.message : String(err)}`));
487 }
488 };
489 const onError = (err: Error) => { cleanup(); reject(err); };
490 const onClose = () => { cleanup(); reject(new Error('daemon closed connection before hello')); };
491 const timer = setTimeout(() => {

Callers

nothing calls this directly

Calls 2

cleanupFunction · 0.70
resolveFunction · 0.50

Tested by

no test coverage detected