MCPcopy Create free account
hub / github.com/EvoMap/evolver / main

Function main

src/adapters/scripts/evolver-session-start.js:476–511  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

474// pipe. This mirrors the stdin-draining pattern in evolver-task-recall.js /
475// evolver-session-end.js.
476function main() {
477 let done = false;
478 let buf = '';
479 const finishWithInput = (input) => {
480 if (done) return;
481 done = true;
482 try {
483 const sessionId = _extractHookSessionId(input);
484 if (sessionId) {
485 recordMarkedSession(sessionId, {
486 cwd: resolveProjectDir(),
487 source: String(process.env.EVOLVER_SESSION_SOURCE || (input && input.source) || '').trim() || undefined,
488 });
489 }
490 } catch (_) { /* marking is best-effort; never block injection */ }
491 runInjection();
492 };
493
494 // Watchdog: if stdin never ends (host passed no pipe, or hangs), proceed
495 // without a session_id rather than stalling the agent's session start.
496 const watchdog = setTimeout(() => finishWithInput(null), 1500);
497 try {
498 process.stdin.setEncoding('utf8');
499 } catch (_) { /* some hosts pass no stdin */ }
500 process.stdin.on('data', (c) => { buf += c; });
501 process.stdin.on('error', () => { clearTimeout(watchdog); finishWithInput(null); });
502 process.stdin.on('end', () => {
503 clearTimeout(watchdog);
504 let input = null;
505 try { input = buf.trim() ? JSON.parse(buf) : null; } catch (_) { input = null; }
506 finishWithInput(input);
507 });
508 // Nudge a resume so a paused stdin stream flushes its data/end events; the
509 // watchdog covers the case where neither ever arrives (no pipe attached).
510 try { process.stdin.resume(); } catch (_) { /* ignore */ }
511}
512
513function runInjection() {
514 if (shouldSkipInjection()) {

Callers 1

Calls 2

finishWithInputFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected