effort

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package effort owns repository-local immutable effort residents and their memory.

Index

Constants

View Source
const SchemaVersion = 2

Variables

View Source
var ErrManagedTopologyPresent = errors.New("managed topology present")

ErrManagedTopologyPresent classifies the restartable-finish refusal that managed Git topology for the slug still exists. Callers branch on errors.Is; the prose stays the user-facing protocol.

Functions

func ListDocument

func ListDocument(records []Record) (presentation.Document, error)

ListDocument maps active efforts in their store-defined slug order.

func RandomUUIDv4

func RandomUUIDv4() (string, error)

RandomUUIDv4 is the production identity allocator. It is exported because the composition root, not this package, decides what allocates an effort's internal identity.

func ValidateCurrentOwner

func ValidateCurrentOwner(path string, info os.FileInfo) error

ValidateCurrentOwner applies the platform's no-follow owner check to an existing path.

func ValidateResidentLeaf

func ValidateResidentLeaf(path string, info os.FileInfo) error

ValidateResidentLeaf applies the whole resident-leaf contract to an already-lstatted path: no symlink, a regular file, exactly one link, and the current owner. The link count is platform knowledge that only this package carries, so a package that must refuse the same unsafe residents shares the check here instead of reimplementing it.

Types

type ActionableOutcome

type ActionableOutcome struct {
	Category        string   `json:"category"`
	Condition       string   `json:"condition"`
	ChangedActivity bool     `json:"changedActivity"`
	NextActions     []string `json:"nextActions"`
	Cause           string   `json:"cause,omitempty"`
}

ActionableOutcome describes a handled refusal and independently executable recovery actions.

type Activity

type Activity struct {
	SchemaVersion int       `json:"schemaVersion"`
	Owner         string    `json:"owner"`
	AttachedAt    time.Time `json:"attachedAt"`
	HeartbeatAt   time.Time `json:"heartbeatAt"`
}

Activity is the optional protocol-v2 advisory claim.

type ActivityCondition

type ActivityCondition string

ActivityCondition identifies the handled protocol-v2 activity result.

const (
	// ActivityAttached reports that the invocation attached a new activity.
	ActivityAttached ActivityCondition = "attached"
	// ActivityTakenOver reports that the invocation replaced a prior activity.
	ActivityTakenOver ActivityCondition = "taken-over"
	// ActivityHeartbeat reports that the invocation refreshed its activity.
	ActivityHeartbeat ActivityCondition = "heartbeat"
	// ActivityDetached reports that the invocation removed its activity.
	ActivityDetached ActivityCondition = "detached"
	// ActivityNotOwner reports that the resident belongs to another owner.
	ActivityNotOwner ActivityCondition = "not-owner"
	// ActivityMissing reports that the requested effort or activity is absent.
	ActivityMissing ActivityCondition = "missing"
	// ActivityInvalidMemory reports that the effort memory is unreadable or invalid.
	ActivityInvalidMemory ActivityCondition = "invalid-memory"
	// ActivityUnsafeResident reports that a resident cannot be safely used.
	ActivityUnsafeResident ActivityCondition = "unsafe-resident"
)

type ActivityEffort

type ActivityEffort struct {
	Slug  string `json:"slug"`
	Title string `json:"title"`
}

ActivityEffort is the immutable effort identity included in successful replies.

type ActivityReply

type ActivityReply struct {
	SchemaVersion int                `json:"schemaVersion"`
	Condition     ActivityCondition  `json:"condition"`
	Effort        *ActivityEffort    `json:"effort,omitempty"`
	Memory        *MemoryMetadata    `json:"memory,omitempty"`
	Activity      *Activity          `json:"activity,omitempty"`
	Outcome       *ActionableOutcome `json:"outcome,omitempty"`
}

ActivityReply is the protocol-v2 envelope returned by activity operations.

type CorruptError

type CorruptError struct {
	Path string
	Err  error
}

CorruptError identifies resident input that must be preserved byte-for-byte.

func (*CorruptError) Diagnostic

func (e *CorruptError) Diagnostic() (presentation.Diagnostic, error)

Diagnostic maps a corrupt resident refusal into the common readable diagnostic.

func (*CorruptError) Error

func (e *CorruptError) Error() string

func (*CorruptError) Unwrap

func (e *CorruptError) Unwrap() error

type Dependencies

type Dependencies struct {
	Clock                 func() time.Time
	UUID                  func() (string, error)
	Worktrees             func(context.Context) ([]awfgit.WorktreeRegistration, error)
	BranchExists          func(context.Context, string) (bool, error)
	ValidateRef           func(context.Context, string) (bool, error)
	RemoveTree            func(string) error
	ExpectedArchiveMarker func() ([]byte, error)
	// Fault is the durability-boundary hook the restartable-finish tests
	// interrupt the service at. It is the one optional member: a nil Fault
	// injects nothing, which is what production wants and what "no fault
	// injection configured" means.
	Fault func(stage string) error
}

Dependencies is everything the service reaches the outside world through: the clock, the identity allocator, the three Git questions it asks, and tree removal. Every one is supplied by the composition root, because a service that quietly substituted its own would make what a caller composed unverifiable from the call site.

The Git dependencies are stated as this package's own questions rather than as a repository object, so the service depends on what it asks and not on who answers. Each is bound to the checkout the service was opened against, so none of them names a root.

type FinishResidentState added in v0.33.0

type FinishResidentState string

FinishResidentState identifies the resident namespace proven at return.

const (
	FinishStateActive   FinishResidentState = "active"
	FinishStateReserved FinishResidentState = "reserved"
	FinishStateArchived FinishResidentState = "archived"
)

type FinishResult

type FinishResult struct {
	State                    FinishResidentState
	Reserved                 bool
	Archived                 bool
	DestinationSyncAvailable bool
	SourceSyncAvailable      bool
	DestinationSynced        bool
	SourceSynced             bool
	ArchivePath              string
}

FinishResult reports each observable namespace and durability boundary.

func (FinishResult) FinishMutation

func (r FinishResult) FinishMutation(slug string) (presentation.Mutation, error)

FinishMutation maps a completed restartable finish into its effort-owned mutation identity, changed axes, and continuation action.

type MemoryCondition added in v0.31.0

type MemoryCondition string

MemoryCondition identifies a successful memory operation or a handled refusal.

const (
	MemoryRead             MemoryCondition = "read"
	MemoryEdited           MemoryCondition = "edited"
	MemoryUpdated          MemoryCondition = "updated"
	MemoryPreviewed        MemoryCondition = "previewed"
	MemoryNotOwner         MemoryCondition = "not-owner"
	MemoryMissing          MemoryCondition = "missing"
	MemoryUnsafeActivity   MemoryCondition = "unsafe-activity"
	MemoryInvalid          MemoryCondition = "invalid-memory"
	MemoryUnsafe           MemoryCondition = "unsafe-memory"
	MemoryOffsetOutOfRange MemoryCondition = "offset-out-of-range"
	MemoryNoMatch          MemoryCondition = "no-match"
	MemoryAmbiguousMatch   MemoryCondition = "ambiguous-match"
	MemoryOverlappingEdits MemoryCondition = "overlapping-edits"
	MemoryResultTooLarge   MemoryCondition = "result-too-large"
	MemoryFailure          MemoryCondition = "memory-failure"
)

type MemoryDiff added in v0.31.0

type MemoryDiff struct {
	Text             string
	FirstChangedLine *int
	Truncated        bool
}

MemoryDiff is a deterministic bounded body-change fact.

type MemoryEditFact added in v0.31.0

type MemoryEditFact struct {
	Index       int
	Occurrences int
}

MemoryEditFact identifies one failed edit and its optional occurrence count.

type MemoryEditInput added in v0.31.0

type MemoryEditInput struct {
	Slug    string
	Owner   string
	Edits   []MemoryReplacement
	Preview bool
}

MemoryEditInput carries one atomic exact-replacement batch.

type MemoryMetadata

type MemoryMetadata struct {
	Effort  string `json:"effort"`
	Phase   string `json:"phase"`
	Next    string `json:"next"`
	Updated string `json:"updated"`
}

MemoryMetadata is the closed, mutable header of an owned memory file.

type MemoryOffsetFact added in v0.31.0

type MemoryOffsetFact struct {
	Offset     int
	TotalLines int
}

MemoryOffsetFact reports a syntactically valid offset beyond the document.

type MemoryOperationInput added in v0.31.0

type MemoryOperationInput interface {
	// contains filtered or unexported methods
}

MemoryOperationInput is the closed input set accepted by Service.Memory.

type MemoryOperationResult added in v0.31.0

type MemoryOperationResult struct {
	Condition        MemoryCondition
	Memory           *MemoryMetadata
	Content          string
	Range            *MemoryRange
	Offset           *MemoryOffsetFact
	ReplacementCount int
	Diff             *MemoryDiff
	Outcome          *MemoryOutcome
	Edit             *MemoryEditFact
	Overlap          *MemoryOverlapFact
	Size             *MemorySizeFact
}

MemoryOperationResult is the closed protocol-neutral result of a memory operation.

func (MemoryOperationResult) MemoryDocument added in v0.31.0

func (r MemoryOperationResult) MemoryDocument() (presentation.Document, error)

MemoryDocument maps every protocol-neutral memory fact to ordinary readable text.

type MemoryOutcome added in v0.31.0

type MemoryOutcome struct {
	Category      string
	Condition     string
	ChangedMemory bool
	NextActions   []RecoveryAction
	Cause         string
}

MemoryOutcome describes a handled refusal without presentation or transport policy.

type MemoryOverlapFact added in v0.31.0

type MemoryOverlapFact struct {
	FirstIndex  int
	SecondIndex int
}

MemoryOverlapFact identifies the original request indexes of an overlapping pair.

type MemoryRange added in v0.31.0

type MemoryRange struct {
	StartLine   int
	EndLine     int
	TotalLines  int
	NextOffset  *int
	TruncatedBy string
}

MemoryRange reports the selected complete-document line range.

type MemoryReadInput added in v0.31.0

type MemoryReadInput struct {
	Slug   string
	Owner  string
	Offset int
	Limit  int
}

MemoryReadInput selects one bounded, one-indexed range from a complete memory document.

type MemoryReplacement added in v0.31.0

type MemoryReplacement struct {
	OldText string
	NewText string
}

MemoryReplacement is one exact body-only replacement.

type MemorySizeFact added in v0.31.0

type MemorySizeFact struct {
	Bytes    int
	MaxBytes int
}

MemorySizeFact reports a rejected complete encoded result size.

type MemoryUpdate

type MemoryUpdate struct {
	Phase *string
	Next  *string
}

MemoryUpdate names the mutable fields requested by a structured update.

type MemoryUpdateInput added in v0.31.0

type MemoryUpdateInput struct {
	Slug    string
	Owner   string
	Update  MemoryUpdate
	Preview bool
}

MemoryUpdateInput carries a structured metadata update and optional advisory owner.

type NewInput

type NewInput struct {
	Slug  string
	Title string
}

NewInput carries the caller-selected immutable identity and independent descriptive title for one effort creation.

type PartialFinishError

type PartialFinishError struct {
	Result  FinishResult
	Cause   error
	Actions []RecoveryAction
}

PartialFinishError preserves a failed restartable finish's observed state, mechanism cause, and site-specific recovery actions.

func (*PartialFinishError) Diagnostic

func (e *PartialFinishError) Diagnostic() (presentation.Diagnostic, error)

Diagnostic maps a partial finish without embedding recovery prose in Cause.

func (*PartialFinishError) Error

func (e *PartialFinishError) Error() string

Error preserves the failed mechanism's message for legacy error callers.

func (*PartialFinishError) Unwrap

func (e *PartialFinishError) Unwrap() error

Unwrap exposes the failed mechanism for identity-aware callers.

type Record

type Record struct {
	SchemaVersion int       `json:"-"`
	ID            string    `json:"id"`
	Slug          string    `json:"slug"`
	Title         string    `json:"title"`
	CreatedAt     time.Time `json:"createdAt"`
	MemoryPath    string    `json:"memoryPath"`
}

Record is the public protocol-2 effort view. SchemaVersion belongs to the containing reply, while static state carries it directly.

func (Record) Detail

func (r Record) Detail() (presentation.Detail, error)

Detail maps one resident record into its ordered readable facts.

func (Record) NewEffortMutation

func (r Record) NewEffortMutation(mutation presentation.Mutation) (presentation.Mutation, error)

NewEffortMutation composes effort-owned identity with worktree-owned creation facts. The caller supplies a mutation already mapped by worktree.

type RecoveryAction

type RecoveryAction struct{ Text string }

RecoveryAction is one independently executable ordered remedy for a failed effort operation. Its meaning remains model-owned until presentation maps it.

type RollbackResult added in v0.33.0

type RollbackResult struct {
	Reserved bool
	Removed  bool
}

RollbackResult reports the narrow failed-creation deletion transition.

type Service

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

Service owns immutable effort residents and restartable finish.

func Open

func Open(roots awfgit.ControlRoots, deps Dependencies) (*Service, error)

Open resolves the resident paths owned by roots and composes the service over the dependencies it is given. The control roots arrive already resolved so one command resolves them once, and so the service and the worktree manager provably reason about the same repository identity.

func (*Service) AttachActivity

func (s *Service) AttachActivity(slug, owner string) ActivityReply

AttachActivity attaches owner to slug, replacing any safe prior activity.

func (*Service) DetachActivity

func (s *Service) DetachActivity(slug, owner string) ActivityReply

DetachActivity removes the activity for slug when owner still owns it.

func (*Service) Finish

func (s *Service) Finish(ctx context.Context, slug string) (FinishResult, error)

func (*Service) HeartbeatActivity

func (s *Service) HeartbeatActivity(slug, owner string) ActivityReply

HeartbeatActivity refreshes the activity for slug when owner still owns it.

func (*Service) InvokingRoot

func (s *Service) InvokingRoot() string

InvokingRoot reports the checkout the service was opened from, so callers can name where execution continues when no managed worktree is created.

func (*Service) List

func (s *Service) List() ([]Record, error)

func (*Service) Memory added in v0.31.0

Memory performs one typed protocol-neutral memory operation.

func (*Service) New

func (s *Service) New(ctx context.Context, input NewInput) (Record, error)

func (*Service) RollbackCreation added in v0.33.0

func (s *Service) RollbackCreation(ctx context.Context, identity Record) (RollbackResult, error)

RollbackCreation removes only the immutable resident created by a failed default worktree transaction. It is deliberately not a finish variant.

func (*Service) Show

func (s *Service) Show(slug string) (Record, error)

func (*Service) UpdateMemory

func (s *Service) UpdateMemory(input MemoryUpdateInput) (MemoryOperationResult, error)

UpdateMemory applies one typed structured metadata update.

Jump to

Keyboard shortcuts

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