MCPcopy Create free account
hub / github.com/Noumena-Network/code / getRenderContext

Function getRenderContext

src/interactiveHelpers.tsx:314–382  ·  view source on GitHub ↗
(exitOnCtrlC: boolean)

Source from the content-addressed store, hash-verified

312 return onboardingShown;
313}
314export function getRenderContext(exitOnCtrlC: boolean): {
315 renderOptions: RenderOptions;
316 getFpsMetrics: () => FpsMetrics | undefined;
317 stats: StatsStore;
318} {
319 let lastFlickerTime = 0;
320 const baseOptions = getBaseRenderOptions(exitOnCtrlC);
321
322 // Log analytics event when stdin override is active
323 if (baseOptions.stdin) {
324 logEvent('ncode_stdin_interactive', {});
325 }
326 const fpsTracker = new FpsTracker();
327 const stats = createStatsStore();
328 setStatsStore(stats);
329
330 // Bench mode: when set, append per-frame phase timings as JSONL for
331 // offline analysis by bench/repl-scroll.ts. Captures the full TUI
332 // render pipeline (yoga → screen buffer → diff → optimize → stdout)
333 // so perf work on any phase can be validated against real user flows.
334 const frameTimingLogPath =
335 process.env.NCODE_FRAME_TIMING_LOG ||
336 process.env.CLAUDE_CODE_FRAME_TIMING_LOG;
337 return {
338 getFpsMetrics: () => fpsTracker.getMetrics(),
339 stats,
340 renderOptions: {
341 ...baseOptions,
342 onFrame: event => {
343 fpsTracker.record(event.durationMs);
344 stats.observe('frame_duration_ms', event.durationMs);
345 if (frameTimingLogPath && event.phases) {
346 // Bench-only env-var-gated path: sync write so no frames dropped
347 // on abrupt exit. ~100 bytes at ≤60fps is negligible. rss/cpu are
348 // single syscalls; cpu is cumulative — bench side computes delta.
349 const line =
350 // eslint-disable-next-line custom-rules/no-direct-json-operations -- tiny object, hot bench path
351 JSON.stringify({
352 total: event.durationMs,
353 ...event.phases,
354 rss: process.memoryUsage.rss(),
355 cpu: process.cpuUsage()
356 }) + '\n';
357 // eslint-disable-next-line custom-rules/no-sync-fs -- bench-only, sync so no frames dropped on exit
358 appendFileSync(frameTimingLogPath, line);
359 }
360 // Skip flicker reporting for terminals with synchronized output —
361 // DEC 2026 buffers between BSU/ESU so clear+redraw is atomic.
362 if (isSynchronizedOutputSupported()) {
363 return;
364 }
365 for (const flicker of event.flickers) {
366 if (flicker.reason === 'resize') {
367 continue;
368 }
369 const now = Date.now();
370 if (now - lastFlickerTime < 1000) {
371 logEvent('ncode_flicker', {

Callers 1

runFunction · 0.85

Calls 8

getMetricsMethod · 0.95
recordMethod · 0.95
appendFileSyncFunction · 0.90
getBaseRenderOptionsFunction · 0.85
createStatsStoreFunction · 0.85
setStatsStoreFunction · 0.85
logEventFunction · 0.50

Tested by

no test coverage detected