Documentation
¶
Overview ¶
Package cli handles command-line argument parsing and event streaming.
Index ¶
- Constants
- func DerivePermBase(sentinelPath string) string
- func GenerateRunID() string
- func NewEventWriter(path string) (*eventWriter, error)
- func OverrideStopReason(stopReason string, cancelled bool, timedOut bool) string
- func ParsePermissionHandler(value string) (*permission.FileHandler, error)
- func Run(args []string) int
- func StartSession(ctx context.Context, provider runtime.Provider, backend string, ...) (runtime.Session, error)
- func WaitForSession(ctx context.Context, provider runtime.Provider, cfg SessionWaitConfig, ...) sessionResult
- func WriteSentinel(path string, exitCode int, sessionID, stopReason, runID string, ...)
- func WriteSentinelWithReason(path string, exitCode int, sessionID, stopReason, runID, reason string, ...)
- type EventMetadata
- type EventSink
- type ProviderLifecycle
- type ProviderTurn
- type ServerDiscovery
- type SessionWaitConfig
- type SessionWaitDeps
Constants ¶
const (
DefaultBackend = "opencode-acp"
)
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 ¶
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 ¶
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 ¶
func OverrideStopReason ¶
func ParsePermissionHandler ¶
func ParsePermissionHandler(value string) (*permission.FileHandler, error)
func StartSession ¶
func WaitForSession ¶
func WaitForSession(ctx context.Context, provider runtime.Provider, cfg SessionWaitConfig, deps SessionWaitDeps) sessionResult
func WriteSentinel ¶
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 ¶
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 ¶
type EventMetadata struct {
// contains filtered or unexported fields
}
func NewEventMetadata ¶
func NewEventMetadata(runID, runLabel, runtimeID string) *EventMetadata
type ProviderLifecycle ¶
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 ¶
func NewProviderLifecycle(provider runtime.Provider) *ProviderLifecycle
func (*ProviderLifecycle) NewTurn ¶
func (l *ProviderLifecycle) NewTurn() *ProviderTurn
func (*ProviderLifecycle) RequestClose ¶
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 ¶
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 ¶
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 ¶
func (t *ProviderTurn) Prompt(ctx context.Context, sessionID, prompt string) error
Prompt admits one provider prompt call into close coordination.
func (*ProviderTurn) RequestCancel ¶
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 ¶
func DiscoverServer ¶
func DiscoverServer(flagURL string, getenv func(string) string) ServerDiscovery
type SessionWaitConfig ¶
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 ¶
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
}