@@ -138,14 +138,35 @@ func (o *OpencodeProvider) runCLI(ctx context.Context, prompt string) (string, e
138138 candidates := opencodeModelCandidates (o .model , o .fallbackModels )
139139 var errors []string
140140 for _ , model := range candidates {
141- cmd := exec .CommandContext (ctx , "opencode" , "run" , "--model" , model , "--" , prompt )
141+ cmd := exec .CommandContext (ctx , "opencode" , "run" , "--model" , model )
142+
143+ stdin , err := cmd .StdinPipe ()
144+ if err != nil {
145+ errors = append (errors , fmt .Sprintf ("%s: error creating stdin pipe: %v" , model , err ))
146+ continue
147+ }
142148
143149 var stdoutBuf , stderrBuf strings.Builder
144150 cmd .Stdout = & stdoutBuf
145151 cmd .Stderr = & stderrBuf
146152
147- if err := cmd .Run (); err != nil {
148- errors = append (errors , fmt .Sprintf ("%s: %v: %s" , model , err , strings .TrimSpace (stderrBuf .String ())))
153+ if err := cmd .Start (); err != nil {
154+ errors = append (errors , fmt .Sprintf ("%s: error starting opencode CLI: %v" , model , err ))
155+ continue
156+ }
157+
158+ _ , writeErr := stdin .Write ([]byte (prompt ))
159+ stdin .Close ()
160+
161+ waitErr := cmd .Wait ()
162+
163+ if writeErr != nil {
164+ errors = append (errors , fmt .Sprintf ("%s: error writing to opencode CLI stdin: %v" , model , writeErr ))
165+ continue
166+ }
167+
168+ if waitErr != nil {
169+ errors = append (errors , fmt .Sprintf ("%s: %v: %s" , model , waitErr , strings .TrimSpace (stderrBuf .String ())))
149170 continue
150171 }
151172
0 commit comments