goose

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package goose implements agent.Adapter against Block's `goose` CLI (the `goose run` non-interactive subcommand). It mirrors agent/droid; the agent package itself stays import-free of harness specifics.

Capabilities().NativeSchema is FALSE: goose's native typed-output path (recipe final_output) is ignored by the claude-code provider. The adapter runs `goose run -q --output-format stream-json --no-session`, concatenates the assistant text deltas, parses a JSON object out of the reassembled final text into a map, and the engine re-validates it against output_schema (engine/schema.go ValidateOutputMap). This is the spec §4.2 layer-2 path (conformance Bucket 15).

Gate independence is structural: every Launch passes --no-session and never a resume/name/session-id/path/fork/interactive flag; ValidateConfig rejects the corresponding with-keys.

Index

Constants

View Source
const AdapterRef = "block/goose"

AdapterRef must match the workflow `uses:` literal byte-for-byte.

Variables

View Source
var DefaultEnvAllowlist = []string{"GOOSE_PROVIDER", "GOOSE_MODEL", "ANTHROPIC_API_KEY", "OPENAI_API_KEY"}

DefaultEnvAllowlist — env names the goose adapter reads. Single source of truth for the CLI --agent-env default and resume's implicit allowlist. The forced opsec knobs (GOOSE_MODE, GOOSE_DISABLE_KEYRING, GOOSE_TELEMETRY_ENABLED, XDG_*) are INJECTED by Launch, not allowlisted. ANTHROPIC_API_KEY overlaps claude's allowlist → defaultAgentEnv dedups (see cli/agent_registry.go).

Functions

This section is empty.

Types

type Adapter

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

Adapter is the agent.Adapter implementation for Block goose. One Adapter per CLI invocation; multiple Launch calls per Adapter; all state read-only after construction (no session state crosses Launch boundaries).

func New

func New(opts ...Option) (*Adapter, error)

New constructs an Adapter.

func (*Adapter) Capabilities

func (*Adapter) Capabilities() agent.Caps

Capabilities returns Caps{NativeSchema: false} — goose structures output via the layer-2 path; the engine validates conformance.

func (*Adapter) Launch

func (a *Adapter) Launch(ctx context.Context, handle container.Handle, inv agent.AgentInvocation) (<-chan agent.AgentEvent, <-chan agent.AgentOutcome, error)

Launch runs `goose run -q --output-format stream-json --no-session ...` inside handle via the streaming Backend.Exec. goose's stream-json emits NDJSON flushed LIVE: "message" deltas (assistant text, incremental), then a terminal "complete" or "error". Launch scans those lines and emits ONE AgentEvent per line as it arrives (the realtime tap renders these live), accumulating assistant text deltas into finalText for the output layer-2 path. γ contract: returns IMMEDIATELY with both channels open; events closes BEFORE outcome (defer LIFO); never reuses a session.

func (*Adapter) Ref

func (*Adapter) Ref() string

Ref returns the agent-runtime identifier this adapter satisfies.

func (*Adapter) RequiredEnv

func (*Adapter) RequiredEnv() []string

RequiredEnv implements agent.CredentialNamer. Returns the CREDENTIAL env var names goose authenticates with (provider-alternatives). The provider itself is selected by with:provider or the GOOSE_PROVIDER env var (F34: with: provider takes precedence — see resolveProvider); GOOSE_PROVIDER and GOOSE_MODEL are config selectors (not credentials) and are intentionally excluded here. Both names are defined in DefaultEnvAllowlist.

func (*Adapter) ValidateConfig

func (a *Adapter) ValidateConfig(with ir.RawConfig) error

ValidateConfig enforces goose's with-schema (droid's 5-step order: session-reject → unknown-key → required-prompt → per-key types → provider-conditional auth). Deterministic (sorted keys); runs twice per node.

func (*Adapter) Version

func (a *Adapter) Version(ctx context.Context, handle container.Handle) (string, error)

Version runs `goose --version` inside handle and parses the leading semver. Recorded in run.started.Runtimes; re-resolved on resume; drift hard-errors.

type ErrMissingAPIKey

type ErrMissingAPIKey struct {
	Provider string
	Key      string
}

ErrMissingAPIKey — ValidateConfig's provider-conditional gate (anthropic/openai) when the resolved provider (with:provider, or else the GOOSE_PROVIDER env — see resolveProvider; F34 gives with:provider precedence) needs a credential that is absent from the adapter env. Provider names which provider resolved so the message doesn't blame GOOSE_PROVIDER when a with:provider was the one that actually selected it.

func (*ErrMissingAPIKey) Error

func (e *ErrMissingAPIKey) Error() string

type ErrRuntimeNotFound

type ErrRuntimeNotFound struct {
	Ref       string
	Container string
	Cause     error
}

ErrRuntimeNotFound — Version failed.

func (*ErrRuntimeNotFound) Error

func (e *ErrRuntimeNotFound) Error() string

func (*ErrRuntimeNotFound) Unwrap

func (e *ErrRuntimeNotFound) Unwrap() error

type ErrSessionReuseAttempted

type ErrSessionReuseAttempted struct{ Key string }

ErrSessionReuseAttempted — a with-key that would re-use a goose session.

func (*ErrSessionReuseAttempted) Error

func (e *ErrSessionReuseAttempted) Error() string

type ErrStreamParse

type ErrStreamParse struct {
	Line  []byte
	Cause error
}

ErrStreamParse backs the parse unit tests; Launch tolerates a stray non-JSON line.

func (*ErrStreamParse) Error

func (e *ErrStreamParse) Error() string

func (*ErrStreamParse) Unwrap

func (e *ErrStreamParse) Unwrap() error

type ErrUnexpectedExit

type ErrUnexpectedExit struct {
	ExitCode int
	Output   string
}

ErrUnexpectedExit is sent (bare) when goose exited with no usable result. Output is the captured STDOUT tail — goose writes diagnostics to stdout; stderr is always empty. The engine default branch maps it to retryable_failure.

func (*ErrUnexpectedExit) Error

func (e *ErrUnexpectedExit) Error() string

type Option

type Option func(*Adapter)

Option configures the Adapter at construction time (functional-options).

func WithBackend

func WithBackend(b container.Backend) Option

WithBackend supplies the container.Backend used by Version and Launch.

func WithEnv

func WithEnv(env map[string]string) Option

WithEnv supplies the env-var allowlist forwarded into each `goose run` exec environment. Copied into agent.SecretEnv (redacts under fmt verbs; json:"-" so secrets never reach the state log). Empty map permitted.

func WithPricing

func WithPricing(t pricing.Table) Option

WithPricing injects the pricing.Table used to derive a USD cost from token usage. Tests pass a self-contained fixture table; production leaves it unset so New defaults it to pricing.Default() (embedded rates ⊕ $AWF_PRICING_FILE).

Jump to

Keyboard shortcuts

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