MCPcopy Create free account
hub / github.com/anomalyco/opencode-bench / runOnce

Function runOnce

src/eval.ts:41–166  ·  view source on GitHub ↗
(
    agentName: string,
    modelId: string,
    taskId: string,
    opts: {
      logger: Logger.Instance;
    },
  )

Source from the content-addressed store, hash-verified

39 }
40
41 async function runOnce(
42 agentName: string,
43 modelId: string,
44 taskId: string,
45 opts: {
46 logger: Logger.Instance;
47 },
48 ) {
49 const agent = Agent.get(agentName);
50 Agent.validateModel(agent, modelId);
51 const task = await Task.get(taskId);
52 const cwd = await mkdtemp(join(tmpdir(), "openreval-"));
53 $.cwd(cwd);
54
55 try {
56 opts.logger.log(`Cloning repository to ${cwd}...`);
57 await cloneRepositoryAtCommit(task.source.repo, task.source.from);
58
59 opts.logger.log(`Running pre-task commands...`);
60 const beforeResults: Record<string, Metric.CommandExecution[]> = {};
61 for (const { name, args } of task.metrics) {
62 if (!args) continue;
63 const cl = opts.logger.child(`[criterion ${name}]`);
64 await runCommands(args.setup, { logger: cl, cwd });
65 const results = await runCommands(args.commands, { logger: cl, cwd });
66 beforeResults[name] = results;
67 }
68
69 opts.logger.log(`Running task...`);
70 let duration = 0;
71 const usage = { input: 0, output: 0, cost: 0 };
72 const actions: string[] = [];
73 for (const { commit, prompt } of task.prompts) {
74 const cl = opts.logger.child(
75 `[prompt ${task.source.repo.split("/")[1]}@${commit.slice(0, 7)}]`,
76 );
77
78 const startedAt = Date.now();
79 const result = await agent.definition.run(modelId, prompt, {
80 cwd,
81 logger: cl,
82 });
83 duration += Date.now() - startedAt;
84
85 // Only accumulate usage from the successful result
86 usage.input += result.usage.input;
87 usage.output += result.usage.output;
88 usage.cost += result.usage.cost;
89
90 // Collect actions from this task
91 actions.push(...result.actions);
92 }
93
94 opts.logger.log(`Scoring...`);
95 await finalizeChanges(task.source.from);
96 const diff = await generateDiff(task.source.from);
97 const allScores = [];
98 for (const { name, weight, args } of task.metrics) {

Callers 1

runFunction · 0.85

Calls 9

cloneRepositoryAtCommitFunction · 0.85
runCommandsFunction · 0.85
finalizeChangesFunction · 0.85
generateDiffFunction · 0.85
judgeScoreFunction · 0.85
averageFunction · 0.85
varianceFunction · 0.85
weightedSumFunction · 0.85
cleanupRepositoryFunction · 0.85

Tested by

no test coverage detected