live

package
v0.3.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: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionSchema            = "awf-live-session-v1"
	PhaseIntentRecorded      = TurnPhase("intent_recorded")
	PhaseProviderTurnStarted = TurnPhase("provider_turn_started")
)
View Source
const LeaseSchema = "awf-live-lease-v1"

Variables

View Source
var (
	ErrLiveHomeDrift          = errors.New("agent/live: live home drift")
	ErrUnsafeRoot             = errors.New("agent/live: unsafe root")
	ErrInvalidSessionKey      = errors.New("agent/live: invalid session key")
	ErrSessionDrift           = errors.New("agent/live: session drift")
	ErrActiveTurnNotClearable = errors.New("agent/live: active turn not clearable")
	ErrActiveTurnMismatch     = errors.New("agent/live: active turn mismatch")
	ErrLiveLeaseConflict      = agent.ErrLiveLeaseConflict
	ErrLiveLeaseStaleOwned    = agent.ErrLiveLeaseStaleOwned
)

Functions

func CheckHomePin

func CheckHomePin(pin HomePin, stateDir string, env map[string]string) error

func CheckSessionDrift

func CheckSessionDrift(existing, next SessionRecord) error

func ClearActiveTurnForRecovery added in v0.3.0

func ClearActiveTurnForRecovery(root Root, adapterRef, sessionKey string) error

ClearActiveTurnForRecovery clears a leftover ActiveTurn as part of a continue-retry (recovery:continue), so a stalled turn's session can resume with a fresh turn. Unlike ClearActiveTurnIfSafe it ABANDONS a turn even at PhaseProviderTurnStarted (the phase that safe-clear refuses) — the provider turn was started server-side but the local process lost it to an idle/stall cancel and the retry loop is now resuming the session in-process. A no-op when there is no ActiveTurn.

EDGE: if that provider turn had actually COMPLETED server-side before the stall (we cancelled while draining its tail), resuming re-generates it — wasted work, and duplicate tool side-effects if the turn had external effects. That is the accepted cost of recovery:continue; recovery:restart avoids it by hard-halting for a clean cross-process replay instead.

Only the interpreter's retry loop drives this (via a PersistentSession adapter on a continue-retry); it must never run on a first attempt, where a leftover ActiveTurn genuinely needs cross-process replay.

func ClearActiveTurnIfSafe

func ClearActiveTurnIfSafe(root Root, adapterRef, sessionKey string) error

func FinalizeCommittedTurn

func FinalizeCommittedTurn(root Root, adapterRef, sessionKey string, turn CommittedTurn) error

func FormatVersion

func FormatVersion(providerVersion, protocolDigest string) string

func LeaseID

func LeaseID(runID string, epoch int, nodePath, sessionKey string) string

func RecordTurnIntent

func RecordTurnIntent(root Root, adapterRef, sessionKey string, turn ActiveTurn) error

func RedactKnownSecretShapes

func RedactKnownSecretShapes(s string) string

func ReleaseLease

func ReleaseLease(root Root, adapterRef, sessionKey, leaseID string) error

func SessionRecordPath

func SessionRecordPath(root Root, adapterRef, sessionKey string) string

func ValidateSessionKey

func ValidateSessionKey(key string) error

func WriteSessionRecord

func WriteSessionRecord(root Root, rec SessionRecord) error

Types

type ActiveTurn

type ActiveTurn struct {
	Phase          TurnPhase `json:"phase"`
	RunID          string    `json:"run_id"`
	NodePath       string    `json:"node_path"`
	CurrentEpoch   int       `json:"current_epoch"`
	NextEpoch      int       `json:"next_epoch"`
	PromptDigest   string    `json:"prompt_digest"`
	LeaseID        string    `json:"lease_id"`
	ProviderTurnID string    `json:"provider_turn_id,omitempty"`
}

type CommittedTurn

type CommittedTurn struct {
	RunID          string `json:"run_id"`
	NodePath       string `json:"node_path"`
	Epoch          int    `json:"epoch"`
	ProviderTurnID string `json:"provider_turn_id"`
	CommittedUnix  int64  `json:"committed_unix"`
}

type HomePin

type HomePin struct {
	Path   string `json:"path"`
	Digest string `json:"digest"`
}

type LeaseRecord

type LeaseRecord struct {
	Schema        string `json:"schema"`
	AdapterRef    string `json:"adapter_ref"`
	SessionKey    string `json:"session_key"`
	OwnerRunID    string `json:"owner_run_id"`
	OwnerPID      int    `json:"owner_pid"`
	OwnerNodePath string `json:"owner_node_path"`
	OwnerEpoch    int    `json:"owner_epoch"`
	LeaseID       string `json:"lease_id"`
	TTLSeconds    int64  `json:"ttl_seconds"`
	AcquiredUnix  int64  `json:"acquired_unix"`
	HeartbeatUnix int64  `json:"heartbeat_unix"`
}

func AcquireLease

func AcquireLease(root Root, req LeaseRequest, now time.Time, runHeld func(string) bool) (LeaseRecord, error)

type LeaseRequest

type LeaseRequest struct {
	AdapterRef    string `json:"adapter_ref"`
	SessionKey    string `json:"session_key"`
	OwnerRunID    string `json:"owner_run_id"`
	OwnerPID      int    `json:"owner_pid"`
	OwnerNodePath string `json:"owner_node_path"`
	OwnerEpoch    int    `json:"owner_epoch"`
	LeaseID       string `json:"lease_id"`
	TTLSeconds    int64  `json:"ttl_seconds"`
}

type Root

type Root struct {
	Path string
	Pin  HomePin
}

func OpenRoot

func OpenRoot(stateDir string, env map[string]string) (Root, error)

type SessionRecord

type SessionRecord struct {
	Schema                 string         `json:"schema"`
	AdapterRef             string         `json:"adapter_ref"`
	SessionKey             string         `json:"session_key"`
	CWD                    string         `json:"cwd,omitempty"`
	CanonicalCWD           string         `json:"canonical_cwd"`
	ProviderSessionID      string         `json:"provider_session_id,omitempty"`
	TmuxSession            string         `json:"tmux_session,omitempty"`
	TranscriptPath         string         `json:"transcript_path,omitempty"`
	OwnerRunID             string         `json:"owner_run_id,omitempty"`
	LastSeenUnix           int64          `json:"last_seen_unix,omitempty"`
	AdapterVersion         string         `json:"adapter_version,omitempty"`
	ProviderBinary         string         `json:"provider_binary,omitempty"`
	ProviderProtocolSchema string         `json:"provider_protocol_schema,omitempty"`
	ActiveTurn             *ActiveTurn    `json:"active_turn,omitempty"`
	LastCommittedTurn      *CommittedTurn `json:"last_committed_turn,omitempty"`
}

func ReadSessionRecord

func ReadSessionRecord(root Root, adapterRef, sessionKey string) (SessionRecord, error)

type TurnPhase

type TurnPhase string

Jump to

Keyboard shortcuts

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