TypeScript
/**
* 벤치 레지스트리 (PRD §11).
* isLocalBench / listLocalBenches / taskIds / difficultyMap / findTask / verify / setupTask.
*/
import { BENCHES } from "../config";
import type { Difficulty, LocalTask } from "./local";
import { LOCAL_TASKS } from "./local";
import { SUBAGENT_TASKS } from "./subagent";
const LOCAL_BENCH_TASKS: Record<string, LocalTask[]> = {
local: LOCAL_TASKS,
subagent: SUBAGENT_TASKS,
};
export function isLocalBench(bench: string): boolean {
return BENCHES[bench]?.local === true && bench in LOCAL_BENCH_TASKS;
}
export function listLocalBenches(): string[] {
return Object.keys(LOCAL_BENCH_TASKS);
}
export function taskIds(bench: string): string[] {
return (LOCAL_BENCH_TASKS[bench] ?? []).map((t) => t.id);
}
export function difficultyMap(bench: string): Record<string, Difficulty> {
const out: Record<string, Difficulty> = {};
for (const t of LOCAL_BENCH_TASKS[bench] ?? []) if (t.difficulty) out[t.id] = t.difficulty;
return out;
}
/** 접두사로 유일하게 찾기(전체 일치 우선). 모든 로컬 벤치 통합 탐색. */
export function findTask(id: string): LocalTask | undefined {
const all = Object.values(LOCAL_BENCH_TASKS).flat();
const exact = all.find((t) => t.id === id);
if (exact) return exact;
const prefix = all.filter((t) => t.id.startsWith(id));
return prefix.length === 1 ? prefix[0] : undefined;
}
export function setupTask(id: string, workDir: string): void {
const t = findTask(id);
if (t?.setup) {
try {
t.setup(workDir);
} catch {
// setup 실패도 fail-soft (verify 가 false 반환)
}
}
}
export function verify(id: string, workDir: string): boolean {
const t = findTask(id);
if (!t) return false;
try {
return t.verify(workDir);
} catch {
return false; // 절대 throw 금지
}
}
export function instructionFor(id: string): string | undefined {
return findTask(id)?.instruction;
}
export type { LocalTask, Difficulty };