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

Function startSession

__tests__/daemon-older-version.test.ts:449–474  ·  view source on GitHub ↗

An agent session: `install`'s launcher, `serve --mcp` in the project.

(install: string | null, env: NodeJS.ProcessEnv = {})

Source from the content-addressed store, hash-verified

447
448 /** An agent session: `install`'s launcher, `serve --mcp` in the project. */
449 function startSession(install: string | null, env: NodeJS.ProcessEnv = {}): Session {
450 const bin = install ? path.join(install, 'dist', 'bin', 'codegraph.js') : BIN;
451 const recorder = recordSpawns(tempDir);
452 const child = spawn(process.execPath, [...WASM_RUNTIME_FLAGS, ...recorder.args, bin, 'serve', '--mcp'], {
453 cwd: tempDir,
454 stdio: ['pipe', 'pipe', 'pipe'],
455 env: {
456 ...process.env,
457 CODEGRAPH_MCP_LOG_ATTACH: '1',
458 CODEGRAPH_DAEMON_IDLE_TIMEOUT_MS: '30000',
459 ...recorder.env,
460 ...env,
461 },
462 }) as ChildProcessWithoutNullStreams;
463 child.on('error', () => { /* ignore */ });
464 child.stdin.on('error', () => { /* ignore */ });
465 const session: Session = { child, stdout: [], stderr: [] };
466 lines(child.stdout, session.stdout);
467 lines(child.stderr, session.stderr);
468 sessions.push(session);
469 send(session, {
470 jsonrpc: '2.0', id: 1, method: 'initialize',
471 params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'test', version: '0.0.0' }, rootUri: `file://${tempDir}` },
472 });
473 return session;
474 }
475
476 function send(session: Session, msg: unknown): void {
477 try { session.child.stdin.write(JSON.stringify(msg) + '\n'); } catch { /* gone */ }

Callers 2

sessionWithDaemonFunction · 0.70

Calls 7

recordSpawnsFunction · 0.90
spawnFunction · 0.85
pushMethod · 0.80
linesFunction · 0.70
sendFunction · 0.70
onMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected