a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
34 lines
1.2 KiB
Go
34 lines
1.2 KiB
Go
// Package opencode is the opencode CLI llm.Provider.
|
|
//
|
|
// It shells out to the user's locally installed `opencode` binary in
|
|
// non-interactive mode (`opencode run`), reusing the existing opencode
|
|
// credentials — no API key in gortex's environment. The prompt is the
|
|
// trailing positional argument and the model uses opencode's
|
|
// `provider/model` form (e.g. "anthropic/claude-sonnet-4-6"). The
|
|
// shared agentcli engine handles spawning, timeout, capture, and
|
|
// structured extraction.
|
|
package opencode
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/zzet/gortex/internal/llm"
|
|
"github.com/zzet/gortex/internal/llm/provider/agentcli"
|
|
)
|
|
|
|
// New constructs the opencode CLI provider, verifying the binary is on
|
|
// $PATH. The prompt is the trailing positional after `run`; the model
|
|
// is passed via `--model`.
|
|
func New(cfg llm.CLIConfig) (llm.Provider, error) {
|
|
return agentcli.New(agentcli.Spec{
|
|
ProviderID: "opencode",
|
|
Model: strings.TrimSpace(cfg.Model),
|
|
ModelFlag: "--model",
|
|
BaseArgs: []string{"run"},
|
|
Delivery: agentcli.DeliveryArg,
|
|
ExtraArgs: append([]string(nil), cfg.Args...),
|
|
Timeout: time.Duration(cfg.TimeoutSeconds) * time.Second,
|
|
}, cfg.Binary, "opencode")
|
|
}
|