bada-terminal / scripts /lib /bong-native-benchmark.js
VanyaJ's picture
Release BADA Terminal v2.1.0 (Enterprise Ontology, NVIDIA auto-ontology, Release Preflight)
d739b1b verified
Raw History Blame Contribute Delete
4.36 kB
// ๊ณต๊ฐœ Google ๊ณ„์ธก๋งŒ์„ ์œ„ํ•œ ์ž„์‹œ ํ™˜๊ฒฝ. ์‚ฌ์šฉ์ž ์„ค์ •ยท์ž๊ฒฉ์˜ ์›๋ฌธ์€ ๋ณต์‚ฌ/์ถœ๋ ฅํ•˜์ง€ ์•Š๋Š”๋‹ค.
// ์„ค๋ช… ๋ฌธ์„œ: docs/specs/bong-native-speech-benchmark.md (v1.0.0)
const fs = require('fs'), path = require('path'), crypto = require('crypto');
const MODEL = 'google/gemini-3.8-flash';
const RESPONSE = '(๊ฐ์ •: ์ฐจ๋ถ„ํ•จ; ์†๋„: ๋ณดํ†ต; ์–ดํˆฌ: ์ •์ค‘ํ•˜๊ฒŒ) ์ž‘์—… ๊ณ„ํš์„ ๋จผ์ € ํ™•์ธํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์‹คํ–‰ ์ „์— ์Šน์ธ์„ ๋ฐ›๊ฒ ์Šต๋‹ˆ๋‹ค.';
function claimOutput(root, requested) {
const scratch = fs.realpathSync(path.join(root, 'scratch')), output = path.resolve(root, requested);
const parent = fs.realpathSync(path.dirname(output));
if (!output.startsWith(path.join(root, 'scratch') + path.sep) || (parent !== scratch && !parent.startsWith(scratch + path.sep))) throw Error('BENCH_OUTPUT');
fs.writeFileSync(output, '', { flag: 'wx', mode: 0o600 }); return output;
}
function isolatedNative(home, nativeHome) {
const installed = path.join(process.env.XDG_CONFIG_HOME || path.join(nativeHome, '.config'), 'opencode');
const data = process.env.XDG_DATA_HOME || path.join(nativeHome, '.local/share');
const protectedFiles = [path.join(installed, 'opencode.json'), path.join(nativeHome, '.opencode/opencode.json'),
path.join(data, 'opencode/auth.json'), path.join(nativeHome, '.claude/settings.json')];
const hash = file => fs.existsSync(file) ? crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex') : null;
const before = protectedFiles.map(hash), configHome = path.join(home, '.config'), config = path.join(configHome, 'opencode');
fs.mkdirSync(config, { recursive: true });
const dependencies = {}, packages = {};
// ์„ค์น˜๋œ ๊ณต๊ฐœ JS ํŒจํ‚ค์ง€ ๋‘ ๊ฐœ๋งŒ ์žฌ์‚ฌ์šฉํ•˜์—ฌ ๋นˆ HOME์—์„œ ๋„ค์ดํ‹ฐ๋ธŒ ์ž๋™ npm ์ค€๋น„๋ฅผ ํ”ผํ•œ๋‹ค.
for (const name of ['@opencode-ai/plugin', '@opencode-ai/sdk']) {
const source = path.join(installed, 'node_modules', name), pkg = JSON.parse(fs.readFileSync(path.join(source, 'package.json')));
fs.cpSync(source, path.join(config, 'node_modules', name), { recursive: true });
dependencies[name] = pkg.version; packages['node_modules/' + name] = { version: pkg.version };
}
fs.writeFileSync(path.join(config, 'package.json'), JSON.stringify({ private: true, dependencies }), { mode: 0o600 });
fs.writeFileSync(path.join(config, 'package-lock.json'), JSON.stringify({ lockfileVersion: 3, packages: { '': { dependencies }, ...packages } }), { mode: 0o600 });
const cwd = path.join(home, 'public-project'); fs.mkdirSync(cwd); fs.mkdirSync(path.join(cwd, '.git'));
fs.mkdirSync(path.join(home, '.claude'));
const userSettings = path.join(nativeHome, '.claude/settings.json');
const headroom = fs.existsSync(userSettings) ? JSON.parse(fs.readFileSync(userSettings)).headroom : undefined;
// ํ˜„์žฌ ๋งˆ์Šคํ‚น ์„ค์ •๋งŒ ๊ฒฉ๋ฆฌ ๋ณต์ œํ•œ๋‹ค. ์ž„์˜ regex๋ฅผ ์—†์• ์„œ ์กฐ๊ธฐ ๊ณต๊ฐœ๋ฅผ ๊ฐ•์ œํ•˜์ง€ ์•Š๋Š”๋‹ค.
fs.writeFileSync(path.join(home, '.claude/settings.json'), JSON.stringify(headroom ? { headroom } : {}), { mode: 0o600 });
const env = { PATH: process.env.PATH, HOME: home, XDG_CONFIG_HOME: configHome, XDG_DATA_HOME: data,
XDG_STATE_HOME: path.join(home, '.state'), XDG_CACHE_HOME: path.join(home, '.cache'),
OPENCODE_DISABLE_AUTOUPDATE: 'true', OPENCODE_DISABLE_MODELS_FETCH: 'true', OPENCODE_DISABLE_DEFAULT_PLUGINS: 'true',
OPENCODE_DISABLE_EXTERNAL_SKILLS: 'true', OPENCODE_DISABLE_CLAUDE_CODE: 'true', OPENCODE_DISABLE_PROJECT_CONFIG: 'true',
OPENCODE_CONFIG_CONTENT: JSON.stringify({ $schema: 'https://opencode.ai/config.json', autoupdate: false, share: 'disabled',
plugin: [], instructions: [], skills: { paths: [] }, enabled_providers: ['google'], disabled_providers: [], model: MODEL,
provider: { google: { models: { 'gemini-3.8-flash': { name: 'Gemini 3.8 Flash', limit: { context: 1048576, output: 1024 } } },
options: { baseURL: 'https://generativelanguage.googleapis.com/v1beta' } } } }) };
for (const key of ['SystemRoot', 'COMSPEC', 'PATHEXT', 'TEMP', 'TMP', 'LANG']) if (process.env[key]) env[key] = process.env[key];
if (process.platform === 'win32') env.USERPROFILE = home;
return { cwd, env, configsUnchanged: () => protectedFiles.every((file, i) => hash(file) === before[i]) };
}
module.exports = { isolatedNative, claimOutput, MODEL, RESPONSE };