Internal

internal/adapters/providers

Package providers adapts external model providers to scafld review dossiers.

import "github.com/nilstate/scafld/v2/internal/adapters/providers"

Package providers adapts external model providers to scafld review dossiers.

Constants

Source: internal/adapters/providers/provider.go:92

const (
	// HostAgentCodex identifies Codex as the agent currently driving scafld.
	HostAgentCodex = "codex"
	// HostAgentClaude identifies Claude as the agent currently driving scafld.
	HostAgentClaude = "claude"
)

Variables

ErrProviderFailed wraps provider transport and execution failures.

Source: internal/adapters/providers/provider.go:21

var ErrProviderFailed = errors.New("provider failed")

Functions

func AutoProviderInfo(opts Selection) (AutoProvider, error)

Source: internal/adapters/providers/provider.go:181

AutoProviderInfo returns the concrete external provider selected by auto.

When scafld can tell which agent is currently driving the task, auto prefers the other installed provider for independent review/hardening. If that other provider is unavailable, auto falls back to the current agent unless fallback is explicitly disabled.

func ClaudeArgs(binary string, model string, sessionID string, mcpConfig string, tool SubmitTool) []string

Source: internal/adapters/providers/provider.go:654

ClaudeArgs builds the argv for restricted Claude execution.

func ClaudeEventName(line string) string

Source: internal/adapters/providers/provider.go:1016

ClaudeEventName extracts a liveness event name from one Claude stream frame.

func ClaudeMCPConfig(scafldBinary string, submissionPath string, tool SubmitTool) string

Source: internal/adapters/providers/provider.go:688

ClaudeMCPConfig returns the single-tool MCP config used by the Claude provider.

func CodexArgs(binary string, root string, outputPath string, model string, schemaPath string) []string

Source: internal/adapters/providers/provider.go:797

CodexArgs builds the argv for read-only Codex review execution.

func DetectHostAgent(environ []string) string

Source: internal/adapters/providers/provider.go:268

DetectHostAgent infers whether scafld is being driven by Codex or Claude. SCAFLD_HOST_AGENT can be set to codex or claude when the host does not expose a recognizable environment marker.

func GeminiArgs(binary string, model string, tool SubmitTool, policyPath string) []string

Source: internal/adapters/providers/provider.go:709

GeminiArgs builds the argv for restricted Gemini execution.

func GeminiEventName(line string) string

Source: internal/adapters/providers/provider.go:1033

GeminiEventName extracts a liveness event name from one Gemini stream frame.

func GeminiPolicyTOML(tool SubmitTool) string

Source: internal/adapters/providers/provider.go:735

GeminiPolicyTOML allows exactly the scafld submit tool in Gemini plan mode.

func GeminiPrompt(prompt string, tool SubmitTool) string

Source: internal/adapters/providers/provider.go:788

GeminiPrompt adds the provider-specific MCP tool name Gemini exposes for the scafld submit channel.

func GeminiSettingsJSON(scafldBinary string, submissionPath string, tool SubmitTool) string

Source: internal/adapters/providers/provider.go:753

GeminiSettingsJSON returns an isolated single-server MCP configuration for Gemini CLI. It is passed through GEMINI_CLI_SYSTEM_SETTINGS_PATH so scafld does not mutate project or user Gemini settings during review.

func HardenDossierSchemaJSON() string

Source: internal/adapters/providers/schema.go:16

HardenDossierSchemaJSON returns the strict structured-output schema used by providers that require every property to be listed in required.

func ReviewDossierSchemaJSON() string

Source: internal/adapters/providers/schema.go:10

ReviewDossierSchemaJSON returns the strict structured-output schema used by providers that require every property to be listed in required.

func Select(opts Selection) (interface { Invoke(context.Context, review.Request) (review.Dossier, error) }, error)

Source: internal/adapters/providers/provider.go:98

Select returns the configured review provider implementation.

func SelectAgent(opts Selection) (Agent, error)

Source: internal/adapters/providers/provider.go:129

SelectAgent returns the configured protocol-neutral provider implementation.

func SelectHarden(opts Selection) (interface { Invoke(context.Context, coreharden.Request) (coreharden.Dossier, error) }, error)

Source: internal/adapters/providers/provider.go:824

SelectHarden returns the configured harden provider implementation.

Types

type Agent

Source: internal/adapters/providers/provider.go:59

Agent is the shared provider transport used by protocol-specific adapters.

type Agent interface {
	InvokeAgent(context.Context, AgentRequest) (AgentResponse, error)
}
Methods
  • InvokeAgent func(context.Context, AgentRequest) (AgentResponse, error)

type AgentRequest

Source: internal/adapters/providers/provider.go:37

AgentRequest is the protocol-neutral prompt request used by review and harden.

type AgentRequest struct {
	TaskID           string
	Prompt           string
	SchemaName       string
	SchemaJSON       string
	StrictSchemaJSON string
	SubmitTool       SubmitTool
}
Fields
  • TaskID string
  • Prompt string
  • SchemaName string
  • SchemaJSON string
  • StrictSchemaJSON string
  • SubmitTool SubmitTool

type AgentResponse

Source: internal/adapters/providers/provider.go:47

AgentResponse is the raw structured payload produced by an agent provider.

type AgentResponse struct {
	Text         string
	Provider     string
	Model        string
	SessionID    string
	OutputFormat string
	EventSummary map[string]int
	Result       execution.Result
	RunErr       error
}
Fields
  • Text string
  • Provider string
  • Model string
  • SessionID string
  • OutputFormat string
  • EventSummary map[string]int
  • Result execution.Result
  • RunErr error

type AutoProvider

Source: internal/adapters/providers/provider.go:85

AutoProvider describes the concrete provider selected for provider:auto.

type AutoProvider struct {
	Provider string
	Model    string
}
Fields
  • Provider string
  • Model string

type ClaudeProvider

Source: internal/adapters/providers/provider.go:403

ClaudeProvider invokes Claude with a restricted read-only toolset and a scafld-owned MCP submit tool for the final dossier.

type ClaudeProvider struct {
	Binary         string
	Model          string
	SessionID      string
	ScafldBinary   string
	SubmissionPath string
	CWD            string
	Env            []string
	Runner         Runner
	Timeout        time.Duration
	IdleTimeout    time.Duration
}
Fields
  • Binary string
  • Model string
  • SessionID string
  • ScafldBinary string
  • SubmissionPath string
  • CWD string
  • Env []string
  • Runner Runner
  • Timeout time.Duration
  • IdleTimeout time.Duration

func Invoke(ctx context.Context, req review.Request) (review.Dossier, error)

Source: internal/adapters/providers/provider.go:473

Invoke sends the review prompt to Claude and parses the resulting dossier.

func InvokeAgent(ctx context.Context, req AgentRequest) (AgentResponse, error)

Source: internal/adapters/providers/provider.go:417

InvokeAgent sends the prompt to Claude and reads the scafld MCP submission.

type CodexProvider

Source: internal/adapters/providers/provider.go:478

CodexProvider invokes Codex in read-only ephemeral review mode.

type CodexProvider struct {
	Binary      string
	Model       string
	SchemaPath  string
	OutputPath  string
	CWD         string
	Env         []string
	Runner      Runner
	Timeout     time.Duration
	IdleTimeout time.Duration
}
Fields
  • Binary string
  • Model string
  • SchemaPath string
  • OutputPath string
  • CWD string
  • Env []string
  • Runner Runner
  • Timeout time.Duration
  • IdleTimeout time.Duration

func Invoke(ctx context.Context, req review.Request) (review.Dossier, error)

Source: internal/adapters/providers/provider.go:546

Invoke sends the review prompt to Codex and parses the resulting dossier.

func InvokeAgent(ctx context.Context, req AgentRequest) (AgentResponse, error)

Source: internal/adapters/providers/provider.go:491

InvokeAgent sends the prompt to Codex and reads its structured output.

type CommandProvider

Source: internal/adapters/providers/provider.go:360

CommandProvider invokes an operator-supplied review command.

type CommandProvider struct {
	Command     string
	CWD         string
	Env         []string
	Runner      Runner
	Timeout     time.Duration
	IdleTimeout time.Duration
}
Fields
  • Command string
  • CWD string
  • Env []string
  • Runner Runner
  • Timeout time.Duration
  • IdleTimeout time.Duration

func Invoke(ctx context.Context, req review.Request) (review.Dossier, error)

Source: internal/adapters/providers/provider.go:397

Invoke sends the review prompt to the command and parses stdout as a dossier.

func InvokeAgent(ctx context.Context, req AgentRequest) (AgentResponse, error)

Source: internal/adapters/providers/provider.go:370

InvokeAgent sends the prompt to the command and returns stdout as the payload.

type GeminiProvider

Source: internal/adapters/providers/provider.go:552

GeminiProvider invokes Gemini CLI in read-only plan mode with a scafld-owned MCP submit tool for the final dossier.

type GeminiProvider struct {
	Binary         string
	Model          string
	ScafldBinary   string
	SubmissionPath string
	SettingsPath   string
	PolicyPath     string
	CWD            string
	Env            []string
	Runner         Runner
	Timeout        time.Duration
	IdleTimeout    time.Duration
}
Fields
  • Binary string
  • Model string
  • ScafldBinary string
  • SubmissionPath string
  • SettingsPath string
  • PolicyPath string
  • CWD string
  • Env []string
  • Runner Runner
  • Timeout time.Duration
  • IdleTimeout time.Duration

func Invoke(ctx context.Context, req review.Request) (review.Dossier, error)

Source: internal/adapters/providers/provider.go:649

Invoke sends the review prompt to Gemini and parses the resulting dossier.

func InvokeAgent(ctx context.Context, req AgentRequest) (AgentResponse, error)

Source: internal/adapters/providers/provider.go:567

InvokeAgent sends the prompt to Gemini and reads the scafld MCP submission.

type HardenProvider

Source: internal/adapters/providers/provider.go:835

HardenProvider adapts shared agent transport to the harden dossier protocol.

type HardenProvider struct {
	Agent Agent
}
Fields
  • Agent Agent

func Invoke(ctx context.Context, req coreharden.Request) (coreharden.Dossier, error)

Source: internal/adapters/providers/provider.go:840

Invoke returns a typed harden dossier from the shared provider transport.

type LocalProvider

Source: internal/adapters/providers/provider.go:326

LocalProvider emits deterministic local review dossiers for development smoke tests.

type LocalProvider struct {
	Messages []string
}
Fields
  • Messages []string

func Invoke(ctx context.Context, req review.Request) (review.Dossier, error)

Source: internal/adapters/providers/provider.go:355

Invoke returns a dossier from configured local messages.

func InvokeAgent(ctx context.Context, req AgentRequest) (AgentResponse, error)

Source: internal/adapters/providers/provider.go:331

InvokeAgent returns a deterministic local payload for development smoke tests.

type Runner

Source: internal/adapters/providers/provider.go:24

Runner is the process execution port required by external providers.

type Runner interface {
	Run(context.Context, execution.Request) (execution.Result, error)
}
Methods
  • Run func(context.Context, execution.Request) (execution.Result, error)

type Selection

Source: internal/adapters/providers/provider.go:64

Selection contains provider choice, model, timeout, and runner configuration.

type Selection struct {
	Provider       string
	Command        string
	Binary         string
	Model          string
	CodexModel     string
	ClaudeModel    string
	GeminiModel    string
	CodexBinary    string
	ClaudeBinary   string
	GeminiBinary   string
	CWD            string
	Runner         Runner
	Timeout        time.Duration
	Idle           time.Duration
	FallbackPolicy string
	HostAgent      string
	CommandExists  func(string) bool
}
Fields
  • Provider string
  • Command string
  • Binary string
  • Model string
  • CodexModel string
  • ClaudeModel string
  • GeminiModel string
  • CodexBinary string
  • ClaudeBinary string
  • GeminiBinary string
  • CWD string
  • Runner Runner
  • Timeout time.Duration
  • Idle time.Duration
  • FallbackPolicy string
  • HostAgent string
  • CommandExists func(string) bool

type SubmitTool

Source: internal/adapters/providers/provider.go:29

SubmitTool describes the provider-side structured submission channel.

type SubmitTool struct {
	Name        string
	Title       string
	Description string
	Command     string
}
Fields
  • Name string
  • Title string
  • Description string
  • Command string