MCPcopy
hub / github.com/codeaashu/claude-code / getRenderContext

Function getRenderContext

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

Source from the content-addressed store, hash-verified

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

Callers 1

runFunction · 0.85

Calls 8

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

Tested by

no test coverage detected