cli

package
v0.27.0 Latest Latest
Warning

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

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

Documentation

Overview

Package cli handles command-line argument parsing and event streaming.

Index

Constants

View Source
const (
	DefaultBackend = "opencode-acp"
)
View Source
const DefaultPermissionClaimTimeout = 0

DefaultPermissionClaimTimeout is the zero value, meaning "no timeout": the resolver waits indefinitely for a connected socket client to answer, falling through to the file-handler (or no-resolver) only when the client disconnects. A non-zero --permission-claim-timeout arms an explicit timer for unattended automation scenarios.

Variables

This section is empty.

Functions

func DerivePermBase added in v0.8.0

func DerivePermBase(sentinelPath string) string

derivePermBase derives the permission handler base path from a sentinel path. Rule: if the path ends in ".done", strip it and append ".perm". Otherwise append ".perm" directly. This mirrors the derive_permission_base function in dispatch-avenor.sh.

func GenerateRunID added in v0.8.0

func GenerateRunID() string

generateRunID returns a random 16-character hex string (8 bytes of entropy). If crypto/rand is unavailable (e.g. fd exhaustion), it falls back to a time+pid-derived ID prefixed with "auto-" so consumers can distinguish it from the normal random form. The fallback is logged to stderr; the function never panics.

func NewEventWriter added in v0.8.0

func NewEventWriter(path string) (*eventWriter, error)

func OverrideStopReason

func OverrideStopReason(stopReason string, cancelled bool, timedOut bool) string

func ParsePermissionHandler added in v0.8.0

func ParsePermissionHandler(value string) (*permission.FileHandler, error)

func Run

func Run(args []string) int

func StartSession added in v0.8.0

func StartSession(ctx context.Context, provider runtime.Provider, backend string, opts runtime.StartOptions, resumeID string) (runtime.Session, error)

func WaitForSession added in v0.8.0

func WaitForSession(ctx context.Context, provider runtime.Provider, cfg SessionWaitConfig, deps SessionWaitDeps) sessionResult

func WriteSentinel added in v0.8.0

func WriteSentinel(path string, exitCode int, sessionID, stopReason, runID string, stderr io.Writer)

WriteSentinel writes the completion sentinel file at path using an atomic tmp+rename strategy. Errors are logged to stderr but never affect the caller's exit code.

func WriteSentinelWithReason added in v0.9.0

func WriteSentinelWithReason(path string, exitCode int, sessionID, stopReason, runID, reason string, stderr io.Writer)

WriteSentinelWithReason writes the completion sentinel file at path using an atomic tmp+rename strategy, with an optional reason line (used for exit code 5 "blocked" sentinels). Errors are logged to stderr but never affect the caller's exit code.

Types

type EventMetadata added in v0.20.0

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

func NewEventMetadata added in v0.20.0

func NewEventMetadata(runID, runLabel, runtimeID string) *EventMetadata

func (*EventMetadata) Stamp added in v0.20.0

func (m *EventMetadata) Stamp(event events.Event) events.Event

type EventSink added in v0.8.0

type EventSink interface {
	Write(events.Event) error
	Close() error
}

type ProviderLifecycle added in v0.25.0

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

ProviderLifecycle coordinates untrusted provider calls with provider close. Close is requested synchronously when no calls remain and otherwise deferred until every admitted Prompt, AnswerPermission, and Cancel call has returned.

func NewProviderLifecycle added in v0.25.0

func NewProviderLifecycle(provider runtime.Provider) *ProviderLifecycle

func (*ProviderLifecycle) NewTurn added in v0.25.0

func (l *ProviderLifecycle) NewTurn() *ProviderTurn

func (*ProviderLifecycle) RequestClose added in v0.25.0

func (l *ProviderLifecycle) RequestClose() <-chan struct{}

RequestClose rejects new tracked calls and closes the provider when all calls already admitted to this lifecycle have returned. It never waits for a live third-party call.

type ProviderTurn added in v0.25.0

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

ProviderTurn gives one session wait an idempotent Cancel operation while all turns on the provider share live-call and close coordination.

func (*ProviderTurn) AnswerPermission added in v0.25.0

func (t *ProviderTurn) AnswerPermission(ctx context.Context, sessionID, requestID string, response runtime.PermissionResponse) error

AnswerPermission admits one provider answer call into close coordination.

func (*ProviderTurn) Prompt added in v0.25.0

func (t *ProviderTurn) Prompt(ctx context.Context, sessionID, prompt string) error

Prompt admits one provider prompt call into close coordination.

func (*ProviderTurn) RequestCancel added in v0.25.0

func (t *ProviderTurn) RequestCancel(sessionID string, timeout time.Duration) <-chan struct{}

RequestCancel starts at most one Cancel for this turn. If another turn's Cancel is still live, both turns share that exact call instead of issuing a concurrent duplicate against the same provider.

type ServerDiscovery

type ServerDiscovery struct {
	URL    string
	Source string
	Mode   string
}

func DiscoverServer

func DiscoverServer(flagURL string, getenv func(string) string) ServerDiscovery

type SessionWaitConfig added in v0.9.0

type SessionWaitConfig struct {
	EventCh                <-chan events.Event
	PromptDone             <-chan error
	InterruptCh            <-chan struct{}
	SessionID              string
	RunID                  string
	RunLabel               string
	PermissionClaimScope   string
	AutoApprove            bool
	PermissionClaimTimeout time.Duration
	ProgressTimeout        time.Duration
	Timeout                <-chan time.Time
	// AcceptSessionID validates an authoritative provider ID before the legacy
	// AdoptSessionID callback is invoked. Rejection is a fatal session identity
	// conflict; continuing on the provisional ID would report false success for
	// a conversation owned by another attempt.
	AcceptSessionID func(string) bool
	AdoptSessionID  func(string)
}

type SessionWaitDeps added in v0.9.0

type SessionWaitDeps struct {
	Writer        EventSink
	FileHandler   *permission.FileHandler
	ControlServer *control.ControlServer
	Stderr        io.Writer
	// ProgressTimerC overrides the progress timer channel; nil preserves the
	// normal wall-clock timer behavior.
	ProgressTimerC <-chan time.Time

	// PreparePermissionClaim lets stable runtimes serialize a reused request ID
	// with direct provider completion. Nil uses ControlServer directly.
	PreparePermissionClaim func(context.Context, string, string, control.PermissionResolverState, []any) bool
	// ProviderTurn coordinates permission answers, cancellation, and eventual
	// provider close with the caller's provider lifecycle. Nil creates a turn
	// suitable for callers that do not own provider teardown.
	ProviderTurn *ProviderTurn
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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