MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / OpenCodeRunner

Class OpenCodeRunner

evals/buffbench/runners/opencode.ts:70–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70export class OpenCodeRunner implements Runner {
71 private cwd: string
72 private env: Record<string, string>
73
74 constructor(cwd: string, env: Record<string, string> = {}) {
75 this.cwd = cwd
76 this.env = env
77 }
78
79 async run(prompt: string): Promise<RunnerResult> {
80 const steps: AgentStep[] = []
81 let totalCostUsd = 0
82
83 return new Promise((resolve, reject) => {
84 let openCodeError: string | undefined
85 const model =
86 this.env.OPENCODE_MODEL || process.env.OPENCODE_MODEL || OPENCODE_MODEL
87 const args = [
88 'run',
89 '--model',
90 model,
91 '--format',
92 'json',
93 '--agent',
94 'build',
95 prompt,
96 ]
97
98 console.log(`[OpenCodeRunner] Running: opencode run --model ${model}`)
99
100 const child = spawn('opencode', args, {
101 cwd: this.cwd,
102 env: {
103 ...process.env,
104 ...this.env,
105 OPENCODE_API_KEY:
106 this.env.OPENCODE_API_KEY || process.env.OPENCODE_API_KEY,
107 },
108 stdio: ['ignore', 'pipe', 'pipe'],
109 })
110
111 let stdoutBuffer = ''
112 let stderr = ''
113
114 const processEvent = (event: OpenCodeEvent) => {
115 if (event.type === 'error') {
116 openCodeError = formatOpenCodeError(event.error)
117 steps.push({
118 type: 'text',
119 text: `[OpenCode error] ${openCodeError}`,
120 })
121 return
122 }
123
124 const part = event.part
125 if (!part) {
126 return
127 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected