runtime

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventChildQuestion = "child.question"
)

Shared runtime event names.

View Source
const MaxPermissionMessageBytes = 64 << 10 // 64 KiB

MaxPermissionMessageBytes is the maximum allowed size for a write-in permission message. Messages are validated as UTF-8 and must not exceed this bound.

View Source
const SessionIDConflictStopReason = "session_id_conflict"

Variables

This section is empty.

Functions

func DecodePermissionMessageJSON

func DecodePermissionMessageJSON(raw json.RawMessage) (string, error)

DecodePermissionMessageJSON decodes a JSON string without accepting the replacement behavior encoding/json applies to malformed UTF-8 or unpaired UTF-16 surrogate escapes.

func ExitCodeForStopReason

func ExitCodeForStopReason(stopReason string) int

ExitCodeForStopReason returns Avenor's locked process exit code for a terminal ACP stop reason.

func IsRetryableFailure

func IsRetryableFailure(exitCode int, stopReason string) bool

IsRetryableFailure reports whether a failed attempt may be retried. Session identity conflicts are fatal: retrying could resume a provisional ID or let an attempt finish without adopting the provider's authoritative session ID.

func NewStartOnlyThinkingError

func NewStartOnlyThinkingError(backend, value string) error

NewStartOnlyThinkingError reports that a backend supports the value only on a new session, not an explicit resume.

func NewUnsupportedThinkingError

func NewUnsupportedThinkingError(backend string) error

NewUnsupportedThinkingError returns the shared unsupported-parameter error.

func NewUnsupportedThinkingValueError

func NewUnsupportedThinkingValueError(backend, value string) error

NewUnsupportedThinkingValueError reports a canonical value that the backend supports in general but cannot apply natively.

func StopReasonForExitCode

func StopReasonForExitCode(exitCode int) string

StopReasonForExitCode is the inverse of ExitCodeForStopReason. Returns an empty string for exit code 1 (generic failure) since there is no canonical stop reason for that case.

func ValidatePermissionMessage

func ValidatePermissionMessage(msg string) error

ValidatePermissionMessage checks that a message is valid UTF-8 and within the size bound. Returns nil for an empty message (ordinary options).

func ValidateThinking

func ValidateThinking(value string) error

ValidateThinking accepts the canonical thinking controls and an empty value.

func ValidateThinkingForBackend

func ValidateThinkingForBackend(backend, value string) error

ValidateThinkingForBackend applies the conservative backend policy after validating the canonical value. This is the start-session policy; explicit resume support is represented separately (see thinkingpolicy.Policies).

func ValidateThinkingForBackendResume

func ValidateThinkingForBackendResume(backend, value string) error

ValidateThinkingForBackendResume applies the conservative backend policy for an explicit resume, distinguishing start-only support from capability gaps.

Types

type AgentResult

type AgentResult struct {
	SessionID   string   `json:"session_id"`
	StopReason  string   `json:"stop_reason"`
	ExitCode    int      `json:"exit_code"`
	OutputFiles []string `json:"output_files,omitempty"`
}

AgentResult holds the result of a completed agent session.

type Capabilities

type Capabilities struct {
	Backend             string
	Permissions         bool
	Resume              bool
	ExternalServerURL   bool
	SubprocessDiscovery bool
	ModelSelection      bool
}

Capabilities describes what a runtime backend supports.

type ChildQuestionPayload

type ChildQuestionPayload struct {
	RuntimeID string `json:"runtime_id"`
	SessionID string `json:"session_id"`
	ChildID   string `json:"child_id"`
	Message   string `json:"message"`
	RequestID string `json:"request_id"`
}

ChildQuestionPayload is the shared contract for child->parent clarification events emitted by the supervisor and consumed by orchestrators.

func (ChildQuestionPayload) Fields

func (p ChildQuestionPayload) Fields() map[string]any

Fields returns the event field map used in events.Event.Fields.

type PermissionResponse

type PermissionResponse struct {
	Allow    bool
	OptionID string
	Message  string
}

PermissionResponse is the response to a permission request.

type Provider

type Provider interface {
	Start(ctx context.Context, opts StartOptions) (Session, error)
	Resume(ctx context.Context, sessionID string) (Session, error)
	Prompt(ctx context.Context, sessionID string, prompt string) error
	Cancel(ctx context.Context, sessionID string) error
	Events(ctx context.Context, sessionID string) (<-chan events.Event, error)
	AnswerPermission(ctx context.Context, sessionID string, requestID string, response PermissionResponse) error
	Capabilities(ctx context.Context) (Capabilities, error)
}

Provider is the interface that all ACP runtime backends must implement.

type Session

type Session struct {
	SessionID string
	Backend   string
	Dir       string
	PID       int // Consumed by longe halt (SIGTERM); set by opencode-acp backend. 0 otherwise.
}

Session represents an active ACP session.

type StartOptions

type StartOptions struct {
	Agent        string
	Label        string
	Dir          string
	ServerURL    string
	Model        string
	AgentProfile string
	Thinking     string
	RuntimeID    string         // supervisor-assigned runtime ID (rt_N), for parent-child routing
	Broker       *broker.Broker // optional shared broker instance; backends may create their own if nil

	// SkipPermissions passes --dangerously-skip-permissions to the agy CLI in
	// headless (non-RPC) transport, where there is no interactive/AnswerPermission
	// path available to approve a tool call. Defaults to false (agy's own
	// default); callers running agy fully non-interactively must opt in.
	// Only consumed by the agy backend today.
	SkipPermissions bool

	// AgyStreamIdleTimeout bounds how long the agy PTY-RPC trajectory
	// subscription may stay silent before the client closes that subscription
	// and recovers through the ordinary snapshot/reopen path. It cancels only
	// the subscription, never the remote cascade. Zero (the default) keeps the
	// previous behaviour, where a silent stream is bounded only by the outer
	// turn deadline. Only consumed by the agy backend today.
	AgyStreamIdleTimeout time.Duration

	// AgyRecoverySnapshotTimeout is the per-call deadline for the agy
	// trajectory snapshot RPC used during recovery, so a blocked server ends
	// that call at its own operation deadline instead of consuming the whole
	// outer turn deadline. Zero (the default) keeps the previous behaviour.
	// Only consumed by the agy backend today.
	AgyRecoverySnapshotTimeout time.Duration
}

StartOptions holds options for starting a new session.

func MergeStartOptions

func MergeStartOptions(base, override StartOptions) StartOptions

MergeStartOptions returns a new StartOptions with non-zero fields from override applied over base. Use this to combine provider-scoped defaults with per-start overrides.

Directories

Path Synopsis
agy
Package broker provides a harness-agnostic run broker for agent communication.
Package broker provides a harness-agnostic run broker for agent communication.
claudecore
terminal
Package terminal provides an abstraction for interactive terminal sessions.
Package terminal provides an abstraction for interactive terminal sessions.

Jump to

Keyboard shortcuts

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