provider

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const ClaudeRemoteApprovalEnv = "BRIDGECTL_CLAUDE_REMOTE_APPROVAL"

ClaudeRemoteApprovalEnv opts Claude sessions into remote (Bridge) approval of Bash permission requests. Experimental; off unless set to "1".

Variables

This section is empty.

Functions

func FilterEnv

func FilterEnv(env []string) []string

FilterEnv returns a filtered environment excluding sensitive variables and variables that interfere with subprocess behaviour.

func OpenCodeServerCapabilities

func OpenCodeServerCapabilities() []string

OpenCodeServerCapabilities returns the capability set for the server-mode provider. This is used for provider capability discovery so clients can choose the appropriate UI.

Types

type ClaudeHooksProvider

type ClaudeHooksProvider struct {
	*ClaudeProvider
	// contains filtered or unexported fields
}

ClaudeHooksProvider keeps the native terminal and observes session-local hooks. Observation works without a telemetry collector or remote service.

func NewClaudeHooksProvider

func NewClaudeHooksProvider(cfg StdioConfig) *ClaudeHooksProvider

NewClaudeHooksProvider builds on ClaudeProvider so hooks mode accepts the same credential sources as the plain provider, mirroring how CodexAppServerProvider builds on CodexProvider.

func (*ClaudeHooksProvider) BuildCommand

func (p *ClaudeHooksProvider) BuildCommand(ctx context.Context, cfg bridge.SessionConfig) (*exec.Cmd, error)

func (*ClaudeHooksProvider) DecideApproval added in v1.4.11

func (p *ClaudeHooksProvider) DecideApproval(_ context.Context, sessionID, pendingID, decision string) error

DecideApproval delivers a remote decision to the session's waiting hook helper. The observer refuses it unless a helper is waiting for exactly this request, so a request already answered in the terminal is never re-answered.

func (*ClaudeHooksProvider) WatchInteraction

func (p *ClaudeHooksProvider) WatchInteraction(_ context.Context, id string, _ bridge.SessionConfig) (<-chan bridge.Interaction, error)

type ClaudeProvider added in v1.4.9

type ClaudeProvider struct {
	*StdioProvider
	// contains filtered or unexported fields
}

ClaudeProvider wraps StdioProvider with Claude-specific auth handling. It accepts either CLAUDE_CODE_OAUTH_TOKEN or the credentials the `claude` CLI stores for itself (see resolveClaudeAuth) as valid authentication, mirroring CodexProvider's treatment of a desktop-local auth.json.

Unlike Codex, no credential is ever seeded or rewritten: the CLI owns its store and reads it directly, so BuildCommand needs no override.

func NewClaudeChatProvider

func NewClaudeChatProvider() *ClaudeProvider

NewClaudeChatProvider creates a stream-JSON provider that runs `claude --output-format stream-json --verbose` without a PTY. stdout is newline-delimited JSON; the supervisor's readLoopStreamJSON parser extracts text and thinking deltas as typed OutputChunks, and (see Supervisor.observeStreamJSONInteraction) derives an authoritative Working/Idle interaction state from the protocol's own message_start/ message_stop turn-boundary events.

This provider does not declare ApprovalStateSupported: bridgectl does not currently wire a response path for Claude's permission/control-request protocol, so it must never claim WaitingForApproval.

func NewClaudeProvider

func NewClaudeProvider(cfg StdioConfig) *ClaudeProvider

NewClaudeProvider creates the interactive PTY-backed Claude provider. RequiredEnv is cleared from the underlying StdioConfig because ClaudeProvider validates auth itself — a configured required_env: ["CLAUDE_CODE_OAUTH_TOKEN"] would otherwise reject a host that is authenticated through the CLI's own credential store.

func (*ClaudeProvider) Health added in v1.4.9

func (p *ClaudeProvider) Health(ctx context.Context) error

func (*ClaudeProvider) HealthWithEnv added in v1.4.9

func (p *ClaudeProvider) HealthWithEnv(ctx context.Context, env []string) error

func (*ClaudeProvider) ValidateStartup added in v1.4.9

func (p *ClaudeProvider) ValidateStartup(ctx context.Context) error

ValidateStartup resolves auth explicitly before probing. CodexProvider gets this for free because its BuildCommand seeds CODEX_HOME and fails when no credential resolves; Claude seeds nothing, so without this check a host with no credentials at all would pass validation and fail later at launch.

type CodexAppServerProvider

type CodexAppServerProvider struct {
	*CodexProvider
	// contains filtered or unexported fields
}

CodexAppServerProvider runs the real Codex TUI against a companion app-server. A session-local protocol relay observes the TUI owner's authoritative state and request identities, and can answer a supported pending input request using its original JSON-RPC response mechanism. Supervisor independently enforces writer ownership before any response. See docs/pending-input-response.md for the verified protocol and boundaries.

func NewCodexAppServerProvider

func NewCodexAppServerProvider(cfg StdioConfig) *CodexAppServerProvider

NewCodexAppServerProvider creates the interaction-observable Codex provider. binary/providerRoot mirror NewCodexProvider's construction.

func (*CodexAppServerProvider) BuildCommand

func (p *CodexAppServerProvider) BuildCommand(ctx context.Context, cfg bridge.SessionConfig) (*exec.Cmd, error)

BuildCommand starts the companion `codex app-server` process, waits for it to become reachable, and returns the *exec.Cmd for `codex --remote ws://127.0.0.1:<port>` — the actual PTY child Supervisor drives exactly like any other interactive provider. The companion is torn down when ctx (the session's own context) is cancelled, whatever the reason.

func (*CodexAppServerProvider) CompanionEndpoint

func (p *CodexAppServerProvider) CompanionEndpoint(sessionID string) (endpoint string, ok bool)

CompanionEndpoint returns the ws:// URL of sessionID's companion app-server, for diagnostics (e.g. `bridgectl doctor`) or a caller that needs to connect its own additional client to the same instance. Returns ok=false once BuildCommand hasn't run yet for this session, or after the session has stopped and its companion was torn down.

func (*CodexAppServerProvider) DecideApproval

func (p *CodexAppServerProvider) DecideApproval(ctx context.Context, sessionID, pendingID, decision string) error

func (*CodexAppServerProvider) ObserveActivity

func (p *CodexAppServerProvider) ObserveActivity(id string, after uint64, events, bytes int) (bridge.ActivityWindow, error)

func (*CodexAppServerProvider) PromptPattern

func (p *CodexAppServerProvider) PromptPattern() *regexp.Regexp

func (*CodexAppServerProvider) RespondToInput

func (p *CodexAppServerProvider) RespondToInput(ctx context.Context, sessionID, pendingID, text string) error

func (*CodexAppServerProvider) SendInstruction

func (p *CodexAppServerProvider) SendInstruction(ctx context.Context, id, text string) error

func (*CodexAppServerProvider) WatchInteraction

func (p *CodexAppServerProvider) WatchInteraction(ctx context.Context, sessionID string, _ bridge.SessionConfig) (<-chan bridge.Interaction, error)

WatchInteraction implements bridge.InteractionWatcher. It is only ever called by Supervisor after BuildCommand has already returned successfully for the same sessionID, so the companion's port is always already known.

type CodexProvider

type CodexProvider struct {
	*StdioProvider
}

CodexProvider wraps StdioProvider with Codex-specific auth handling. It accepts either OPENAI_API_KEY / CODEX_API_KEY (API-key auth) or CODEX_AUTH / CODEX_HOME auth.json (ChatGPT account auth) as valid authentication.

CODEX_AUTH bootstraps a desktop-local auth.json once. Codex owns subsequent refreshes; only an explicit operator rotation should remove that file.

func NewCodexProvider

func NewCodexProvider(cfg StdioConfig) *CodexProvider

NewCodexProvider creates a Codex provider that supports both API-key and device-code authentication. RequiredEnv is cleared from the underlying StdioConfig because CodexProvider validates auth itself.

func (*CodexProvider) BuildCommand

func (p *CodexProvider) BuildCommand(ctx context.Context, cfg bridge.SessionConfig) (*exec.Cmd, error)

func (*CodexProvider) Cleanup

func (p *CodexProvider) Cleanup()

Cleanup leaves desktop-owned auth, helper binaries, and session state intact.

func (*CodexProvider) Health

func (p *CodexProvider) Health(ctx context.Context) error

func (*CodexProvider) HealthWithEnv

func (p *CodexProvider) HealthWithEnv(ctx context.Context, env []string) error

func (*CodexProvider) ValidateStartup

func (p *CodexProvider) ValidateStartup(ctx context.Context) error

type OpenCodeServerConfig

type OpenCodeServerConfig struct {
	ProviderID     string
	Binary         string
	DefaultArgs    []string
	StartupTimeout time.Duration
	StopGrace      time.Duration
	RequiredEnv    []string
	// Hostname to bind the OpenCode server to. Defaults to "127.0.0.1".
	Hostname string
	// PortRangeStart is the beginning of the port range for allocating server
	// ports. Defaults to 4100.
	PortRangeStart int
	// PortRangeEnd is the end of the port range (exclusive). Defaults to 4200.
	PortRangeEnd int
	// ProviderRoot is an optional absolute path used as the base for resolving
	// relative binary paths. When empty, relative paths are resolved against
	// the daemon working directory.
	ProviderRoot string
}

OpenCodeServerConfig configures the headless OpenCode server-mode provider. The bridge launches `opencode serve` on a localhost port and communicates with the OpenCode HTTP/SSE API instead of driving a PTY.

type OpenCodeServerProvider

type OpenCodeServerProvider struct {
	// contains filtered or unexported fields
}

OpenCodeServerProvider implements bridge.Provider for the OpenCode server mode. Instead of a PTY, it launches `opencode serve` as a subprocess and exposes a structured HTTP/SSE interface.

For v1, the provider launches one `opencode serve` process per session via BuildCommand. The returned *exec.Cmd runs `opencode serve` bound to a localhost port. The supervisor still manages the subprocess lifecycle, but the provider advertises itself as a StreamJSON provider so the supervisor reads structured JSONL from stdout instead of raw PTY bytes.

The provider resolves a free localhost port at BuildCommand time and injects the --hostname and --port flags. The OpenCode server's HTTP API base URL is stored per-session in the provider for future use by message-oriented RPCs (SendMessage, AbortTurn, etc. -- planned in a later phase).

func NewOpenCodeServerProvider

func NewOpenCodeServerProvider(cfg OpenCodeServerConfig) *OpenCodeServerProvider

NewOpenCodeServerProvider creates a headless OpenCode server-mode provider.

func (*OpenCodeServerProvider) AbortTurn

func (p *OpenCodeServerProvider) AbortTurn(ctx context.Context, sessionID string) error

AbortTurn sends an abort request to the active OpenCode server session.

TODO(#108): Wire into bridge AbortTurn RPC when proto additions land.

func (*OpenCodeServerProvider) Binary

func (p *OpenCodeServerProvider) Binary() string

func (*OpenCodeServerProvider) BuildCommand

func (p *OpenCodeServerProvider) BuildCommand(ctx context.Context, cfg bridge.SessionConfig) (*exec.Cmd, error)

BuildCommand constructs the `opencode serve` command for a session. It allocates a free localhost port, constructs the server flags, and returns the exec.Cmd. The supervisor owns the subprocess lifecycle.

func (*OpenCodeServerProvider) CleanupSession

func (p *OpenCodeServerProvider) CleanupSession(sessionID string)

CleanupSession removes tracked session metadata. Should be called when the session is stopped.

func (*OpenCodeServerProvider) Health

Health checks that the binary exists, is executable, and required env is set.

func (*OpenCodeServerProvider) HealthWithEnv

func (p *OpenCodeServerProvider) HealthWithEnv(ctx context.Context, env []string) error

HealthWithEnv checks health using the provided environment.

func (*OpenCodeServerProvider) ID

func (*OpenCodeServerProvider) IsStreamJSON

func (p *OpenCodeServerProvider) IsStreamJSON() bool

IsStreamJSON returns true. The OpenCode server provider emits structured output on stdout that the supervisor should parse as JSONL.

func (*OpenCodeServerProvider) PromptPattern

func (p *OpenCodeServerProvider) PromptPattern() *regexp.Regexp

func (*OpenCodeServerProvider) SendPrompt

func (p *OpenCodeServerProvider) SendPrompt(ctx context.Context, sessionID, prompt string) error

SendPrompt sends a user prompt to an active OpenCode server session. This is a placeholder for v1; the full implementation will use the OpenCode session and message APIs.

TODO(#108): Implement full prompt/message sending via OpenCode HTTP API once the bridge proto adds SendMessage/AbortTurn RPCs.

func (*OpenCodeServerProvider) SessionBaseURL

func (p *OpenCodeServerProvider) SessionBaseURL(sessionID string) (string, error)

SessionBaseURL returns the HTTP base URL for a running OpenCode server session, or an error if the session is not tracked.

func (*OpenCodeServerProvider) SetUnavailable

func (p *OpenCodeServerProvider) SetUnavailable(err error)

SetUnavailable persists a startup-time error so that Health() reports the provider as unavailable.

func (*OpenCodeServerProvider) StartupTimeout

func (p *OpenCodeServerProvider) StartupTimeout() time.Duration

func (*OpenCodeServerProvider) StopGrace

func (p *OpenCodeServerProvider) StopGrace() time.Duration

func (*OpenCodeServerProvider) SubscribeSSE

func (p *OpenCodeServerProvider) SubscribeSSE(ctx context.Context, sessionID string) (<-chan SSEEvent, error)

SubscribeSSE connects to the OpenCode server's SSE event stream and sends parsed events to the returned channel. The caller should cancel the context to stop the subscription.

TODO(#108): Map OpenCode SSE events into bridge OutputChunk types once the event schema is finalized.

func (*OpenCodeServerProvider) ValidateStartup

func (p *OpenCodeServerProvider) ValidateStartup(ctx context.Context) error

ValidateStartup checks that required environment variables are set.

func (*OpenCodeServerProvider) Version

func (p *OpenCodeServerProvider) Version(ctx context.Context) (string, error)

Version runs `<binary> --version` to report the provider version.

func (*OpenCodeServerProvider) WaitForHealth

func (p *OpenCodeServerProvider) WaitForHealth(ctx context.Context, sessionID string) error

WaitForHealth polls the OpenCode server's health endpoint until it responds with 200 or the context is cancelled. This should be called after the subprocess is started and before sending any API requests.

type SSEEvent

type SSEEvent struct {
	Event string
	Data  string
	ID    string
}

SSEEvent represents a parsed Server-Sent Event from the OpenCode server.

type StdioConfig

type StdioConfig struct {
	ProviderID     string
	Binary         string
	DefaultArgs    []string
	StartupTimeout time.Duration
	StopGrace      time.Duration
	StartupProbe   string
	PromptPattern  string
	RequiredEnv    []string
	StreamJSON     bool // if true, the provider uses stream-JSON mode (no PTY)
	StripANSI      bool // if true, ANSI escape codes are stripped from PTY output
	// ProviderRoot is an optional absolute path used as the base for resolving
	// relative Binary and DefaultArgs paths. When empty, relative paths are
	// resolved against the daemon working directory (legacy behaviour).
	ProviderRoot string
	// InteractionCapabilities declares what this provider configuration can
	// authoritatively report about interaction state (see
	// bridge.InteractionCapableProvider). The zero value (all false) is
	// correct for any provider that has no wired structured signal:
	// Supervisor then only ever reports InteractionUnknown for it, never a
	// guess.
	InteractionCapabilities bridge.InteractionCapabilities
}

StdioConfig configures an interactive PTY-backed provider.

type StdioProvider

type StdioProvider struct {
	// contains filtered or unexported fields
}

StdioProvider defines how to launch and validate one interactive CLI.

func NewOpenCodeProvider

func NewOpenCodeProvider() *StdioProvider

NewOpenCodeProvider creates the interactive PTY-backed OpenCode provider.

func NewStdioProvider

func NewStdioProvider(cfg StdioConfig) *StdioProvider

func (*StdioProvider) Binary

func (p *StdioProvider) Binary() string

func (*StdioProvider) BuildCommand

func (p *StdioProvider) BuildCommand(ctx context.Context, cfg bridge.SessionConfig) (*exec.Cmd, error)

func (*StdioProvider) Health

func (p *StdioProvider) Health(ctx context.Context) error

func (*StdioProvider) HealthWithEnv

func (p *StdioProvider) HealthWithEnv(ctx context.Context, env []string) error

func (*StdioProvider) ID

func (p *StdioProvider) ID() string

func (*StdioProvider) InteractionCapabilities

func (p *StdioProvider) InteractionCapabilities() bridge.InteractionCapabilities

InteractionCapabilities implements bridge.InteractionCapableProvider. It returns the zero value (every field false) for any configuration that does not explicitly set InteractionCapabilities, which is the correct, honest report for a provider with no wired structured signal.

func (*StdioProvider) IsStreamJSON

func (p *StdioProvider) IsStreamJSON() bool

IsStreamJSON implements bridge.StreamJSONProvider. It returns true when the provider is configured with StreamJSON: true (i.e. it emits JSONL on stdout instead of raw PTY bytes).

func (*StdioProvider) IsStripANSI

func (p *StdioProvider) IsStripANSI() bool

IsStripANSI implements bridge.StripANSIProvider. It returns true when the provider is configured with StripANSI: true so the supervisor strips ANSI escape codes from PTY output before forwarding to clients.

func (*StdioProvider) PromptPattern

func (p *StdioProvider) PromptPattern() *regexp.Regexp

func (*StdioProvider) SetUnavailable

func (p *StdioProvider) SetUnavailable(err error)

SetUnavailable persists a startup-time error so that Health() reports the provider as unavailable until the process restarts. Used by the daemon to propagate startup-probe failures into the runtime health state.

func (*StdioProvider) StartupTimeout

func (p *StdioProvider) StartupTimeout() time.Duration

func (*StdioProvider) StopGrace

func (p *StdioProvider) StopGrace() time.Duration

func (*StdioProvider) ValidateStartup

func (p *StdioProvider) ValidateStartup(ctx context.Context) error

func (*StdioProvider) Version

func (p *StdioProvider) Version(ctx context.Context) (string, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL