Lines 89-129javascript
89async function askOpenAI(model, system, user) {
90 const res = await fetch('https://api.openai.com/v1/chat/completions', {
92 headers: { 'content-type': 'application/json', authorization: `Bearer ${process.env.OPENAI_API_KEY}` },
93 body: JSON.stringify({ model, temperature: 0, max_tokens: 500,
94 messages: [{ role: 'system', content: system }, { role: 'user', content: user }] }),
95 signal: AbortSignal.timeout(60000),
97 if (!res.ok) throw new Error(`openai ${res.status}: ${(await res.text()).slice(0, 300)}`);
98 const j = await res.json();
99 return j.choices?.[0]?.message?.content || '';
102const SYSTEM = 'You are a senior React / React Native advisor. Answer the question directly and concisely (a few sentences). It is currently 2026.';
104// ── subscription fallback: ask via the Claude Code CLI (`claude -p`) ────────────
105// NON-REFERENCE conditions, labeled as such in the results: no temperature control,
106// answers ride the Claude Code wrapper (system prompt REPLACED to strip the coding-CLI
107// framing), and it consumes the operator's subscription quota. Isolation: runs in an
108// EMPTY scratch cwd with MCP + tools locked out so the model cannot read the corpus
109// it is being benchmarked against.
110import { execFileSync } from 'node:child_process';
111import { mkdtempSync } from 'node:fs';
HighChild Process
Package source references child process execution.
tools/react-brain-bench.mjsView on unpkg · L109 112import { tmpdir } from 'node:os';
113let _cliScratch = null;
114function askClaudeCli(model, system, user) {
115 if (!_cliScratch) _cliScratch = mkdtempSync(join(tmpdir(), 'rb-bench-'));
116 return execFileSync('claude', [
119 '--system-prompt', system,
120 '--max-turns', '3', // room to recover from a DENIED tool attempt into a text answer
121 '--strict-mcp-config', // no MCP servers — the corpus MCP must not leak in
122 '--disallowedTools', 'Bash', 'Read', 'Write', 'Edit', 'Glob', 'Grep', 'WebFetch', 'WebSearch', 'Agent', 'Task',
123 ], { encoding: 'utf8', cwd: _cliScratch, timeout: 180000, maxBuffer: 4 * 1024 * 1024 }).trim();
126async function run({ model, withCorpus, limit, today, viaCli = false }) {
127 const provider = viaCli ? 'claude-code-cli' : /^claude|^anthropic/i.test(model) ? 'anthropic' : 'openai';
129 const key = provider === 'anthropic' ? process.env.ANTHROPIC_API_KEY : process.env.OPENAI_API_KEY;