claim

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package claim is the reservation on the shared remote: before a person's agent starts on an issue or an intent, it reserves the record as a branch nobody merges, `refs/heads/abcd-reserved/<record-id>` on `origin`, so every participant — a second person, a second computer, a hosted cloud session — sees the reservation before starting the same item (itd-2609091034175565, adr-2610031352212697: claims are branches on the shared remote, never a hidden ref, because a hosted session's proxy refuses pushes outside refs/heads/).

A reservation is a chain of empty-tree commits written with `git commit-tree`, whose trailers name the record, the holder (a GitHub username), the working copy, the footprint and the lease. Every act is one plain fast-forward push, which is already the compare-and-swap: the remote takes it only when the tip the writer judged is still the tip.

Every surface a person reads says reservation; inside the code it is a claim, the name the in-run claim in internal/core/implement already uses. Both are judged by internal/core/lease.

The package owns the message format and its reader, the holder, the working-copy key, the fetch, the push protocol and the derived release. It never writes to stdout: a front door renders its results and refusals.

Index

Constants

View Source
const (
	// Remote is the one remote reservations live on.
	Remote = "origin"
	// RefPrefix is where a reservation branch sits on the remote, and
	// TrackingPrefix where this checkout keeps what it last fetched of them.
	// The prefix is disjoint from the implement loop's lane prefix build/.
	RefPrefix      = "refs/heads/abcd-reserved/"
	TrackingPrefix = "refs/remotes/" + Remote + "/abcd-reserved/"

	// MaxMessageBytes caps a reservation commit's message: the writer refuses
	// a longer one and the reader reads one as unreadable.
	MaxMessageBytes = 4096

	// TakeoverMargin is how long past a reservation's effective expiry (or an
	// unreadable tip's hold) another person waits before taking it over, by
	// the taker's clock: the slack that absorbs small skew between clocks,
	// and the only slack. It is lease.Skew, the allowance within which a
	// reservation dated ahead of the reader is still judged by its own dates.
	// A holder whose clock runs behind by more than half its lease plus this
	// margin can be taken over between its renewals;
	// nothing on the reader's side bounds it, since the commit date comes
	// from the same clock (spc-2610031753359849, the review of 2026-10-14).
	TakeoverMargin = lease.Skew
)
View Source
const (
	NotHeldAbsent        = "absent"
	NotHeldUnreadable    = "unreadable"
	NotHeldReleased      = "released"
	NotHeldAnotherPerson = "another_person"
	NotHeldAnotherCopy   = "another_copy"
	NotHeldLapsed        = "lapsed"
)

Why a renewal found no reservation of this person's from this copy to renew.

View Source
const (
	CopyThis    = "this"
	CopyAnother = "another"
)

The copy a reservation was made from, as a result names it: never another copy's key.

View Source
const (
	LineNone    = "none"
	LineUnknown = "unknown"
)

The record render's words for a record with no reservation to show: none in a view abcd fetched, or unknown in one nothing here fetched, which is never read as free.

View Source
const (
	LineThisCopy    = "this copy"
	LineAnotherCopy = "another copy"
)

Whose copy a reservation is from, when it is the reader's own.

View Source
const (
	StateLive       = "live"
	StateExpired    = "expired"
	StateReleased   = "released"
	StateUnreadable = "unreadable"
)

The states a listing shows a reservation in.

View Source
const (
	ReleasedByTombstone     = "tombstone"
	ReleasedByDefaultBranch = "default-branch"
)

What released a reservation: its own tombstone, or the record finished on origin's default branch (the derived release).

View Source
const MaxLive = 10

MaxLive is the most live reservations one person may hold, counted by username across every record in the view: a laptop and a cloud session that resolve to one username are one person.

Variables

View Source
var (
	ErrBackOff = errors.New("the record is reserved")
	ErrRefused = errors.New("the reservation was refused")
)

ErrBackOff marks a refusal whose remedy is to take other work: the record is held, and the front door exits 3, as `implement claim` does for contention. ErrRefused marks every other refusal and failure, exit 2.

View Source
var ErrNoOrigin = errors.New("this checkout has no remote named origin")

ErrNoOrigin is Fetch's answer for a checkout with no remote named origin: there are no reservations to read, which is not a failed fetch.

Functions

func Fetch

func Fetch(root string, o Options) (gap string, err error)

Fetch reads every reservation branch from origin, with pruning, and the default branch, and stamps when it did, as every act does before it judges; it is the listing's one network act. gap is why the default branch could not be read, when it could not. A checkout with no remote named origin answers ErrNoOrigin. After a fetch it keeps, for each tip dated more than lease.Skew ahead (and each whose date cannot be read), when this copy first fetched it, so the view, which writes nothing, counts it from then.

func HasOrigin

func HasOrigin(root string) (bool, error)

HasOrigin reports whether the checkout at root has a remote named origin, the one reservations live on, reading only its configuration.

func NoReplyUsername

func NoReplyUsername(email string) string

NoReplyUsername is the GitHub username a noreply commit address names, or "" when the address is not one.

func ReaderHolder added in v0.15.0

func ReaderHolder(root string, o Options) string

ReaderHolder is the GitHub username the person reading resolves to, read as a reservation verb reads it, with no network act; "" when it cannot be told. A render that tells this person's other copy apart from another person reads it.

func SameHolder added in v0.15.0

func SameHolder(a, b string) bool

SameHolder reports whether two usernames name one person, compared without regard to case, as the forge compares them.

Types

type Act

type Act string

Act is what a reservation verb did.

const (
	ActReserved        Act = "reserved"
	ActRenewed         Act = "renewed"
	ActTakenOver       Act = "taken_over"
	ActReleased        Act = "released"
	ActAlreadyReleased Act = "already_released"
)

type FetchError

type FetchError struct {
	Reason string
	// contains filtered or unexported fields
}

FetchError is a failed fetch from origin: Reason is git's own, home-redacted, which a caller quotes in its own refusal (the land fence). It is an ErrRefused refusal: nothing was made. The reservations' fetch names them, and every other fetch names what it read.

func (*FetchError) Error

func (e *FetchError) Error() string

func (*FetchError) Is

func (e *FetchError) Is(target error) bool

type Line

type Line struct {
	State           string `json:"state"`
	Holder          string `json:"holder,omitempty"`
	Copy            string `json:"copy,omitempty"`
	EffectiveExpiry string `json:"effective_expiry,omitempty"`
	ReleasedBy      string `json:"released_by,omitempty"`
	Unreadable      string `json:"unreadable,omitempty"`
	FetchedAt       string `json:"fetched_at,omitempty"`
	AgeSeconds      *int64 `json:"age_seconds,omitempty"`
	Text            string `json:"text"`
}

Line is one record's reservation as the record render shows it, read from this checkout's disk alone: its state (a view state, or LineNone or LineUnknown), its holder and expiry, whose copy it is when it is the reader's own, the view's age, and the sentence the text form prints.

func LineFor

func LineFor(root, id string, now time.Time, o Options) (l Line, ok bool)

LineFor is id's reservation as last fetched, for the record render: no fetch and no push. ok is false when id is not reservable or the checkout has no remote named origin, where there are no reservations to show. A view no abcd fetch stamped, holding nothing for id, is LineUnknown: a render never says a record is free on a view it cannot date.

type NotHeld

type NotHeld struct {
	Record string
	// Why is one of the NotHeld* reasons.
	Why string
	// Holder is the tip's holder, for another person's or another copy's.
	Holder string
	// Expiry is the tip's effective expiry, or an unreadable tip's hold.
	Expiry time.Time
	// ReleasedAt is a tombstone's time; Derived is true instead when the
	// record is finished on origin's default branch.
	ReleasedAt time.Time
	Derived    bool
	// Unreadable is why the tip cannot be read.
	Unreadable string
	// contains filtered or unexported fields
}

NotHeld is the refusal of an act that needs this person's own reservation from this copy — a renewal, or a release — when the tip is not one: Why names what it is instead, with what the tip says of it, so a caller words its own refusal (the land fence) without reading the message. It pushes nothing.

func (*NotHeld) Error

func (e *NotHeld) Error() string

func (*NotHeld) Is

func (e *NotHeld) Is(target error) bool

type Options

type Options struct {
	// Now is the clock; nil means time.Now.
	Now func() time.Time
	// Home is the home directory the machine layer of the configuration is
	// read under; "" means the process's own.
	Home string
	// Version is the binary's version the Assisted-by label names; "" means
	// the running binary's (core.Version).
	Version string
}

Options carries what a caller may set about the environment an act runs in.

type PushError

type PushError struct {
	Reason string
}

PushError is a reservation push origin refused, for a reason other than a tip the act cannot take: Reason is git's own rejection, home-redacted. It is an ErrRefused refusal: no reservation was made.

func (*PushError) Error

func (e *PushError) Error() string

func (*PushError) Is

func (e *PushError) Is(target error) bool

type Replaced

type Replaced struct {
	// Holder is whose it was; "" for an unreadable tip.
	Holder string
	// Copy is CopyAnother when it was this person's other copy, else "".
	Copy string
	// Commit is the tip replaced.
	Commit string
	// EffectiveExpiry is when it stopped holding (an unreadable tip's hold).
	EffectiveExpiry time.Time
	// Unreadable is why the tip could not be read, "" when it could.
	Unreadable string
}

Replaced is the reservation a take-over replaced.

type Request

type Request struct {
	// Record is the issue or intent id, as the person typed it.
	Record string
	// Footprint is the repository-relative files the work will change; a
	// reservation requires at least one, a release takes none.
	Footprint []string
	// Lease is how long the reservation holds; zero means lease.Default.
	Lease time.Duration
	// TakeOver moves this person's own live reservation from another copy to
	// this one. It never overrides another person's.
	TakeOver bool
	// Release pushes the tombstone instead.
	Release bool
	// Renew renews this person's own reservation from this copy, live or
	// lapsed, and nothing else: an absent, unreadable or released tip, and one
	// another person or another copy holds, is refused with a *NotHeld naming
	// why, and nothing is pushed. A run's renewal therefore never reserves a
	// record anew and never takes one over. It keeps the tip's footprint, so
	// Footprint must be empty.
	Renew bool
	// Live, with Renew, refuses one's own reservation that has lapsed too
	// (NotHeldLapsed): the land fence renews only a reservation that holds.
	Live bool
}

Request is one reservation act asked for.

type Reservation

type Reservation struct {
	Record string
	// Holder is the GitHub username the tip names; "" when it is unreadable.
	Holder string
	// Copy is CopyThis when the tip names this checkout's own copy, else "".
	Copy      string
	Footprint []string
	ClaimedAt time.Time
	// EffectiveExpiry is when it stops holding: the lease clamped to a day,
	// or an unreadable tip's hold. A tip dated more than lease.Skew ahead of
	// the reader counts from when this copy first fetched it (lease.Judge).
	EffectiveExpiry time.Time
	// State is StateLive, StateExpired, StateReleased or StateUnreadable.
	State string
	// ReleasedBy says which release, when State is StateReleased.
	ReleasedBy string
	// Unreadable is the fixed reason the tip cannot be read.
	Unreadable string
	// HeldFromFetch is true when an unreadable tip's hold is counted from
	// when this copy first fetched it, its commit date being unreadable.
	HeldFromFetch bool
	Commit        string
}

Reservation is one reservation as the view holds it. Every value in it is data a writer chose: a surface quotes it and never treats it as instruction.

type Result

type Result struct {
	Act    Act
	Record string
	Holder string
	// Copy is CopyThis for every act that pushed, and for a release found
	// already made, whether the tombstone came from this copy.
	Copy      string
	Footprint []string
	ClaimedAt time.Time
	ExpiresAt time.Time
	// Commit is the commit pushed, or the tombstone already there.
	Commit   string
	Replaced *Replaced
	// DerivedUnchecked is why origin's default branch could not be read, so
	// whether the record is already finished there was not checked; "" when
	// it was read (or origin has none).
	DerivedUnchecked string
}

Result is a reservation act that reached the remote, or a release that found nothing to do.

func Reserve

func Reserve(root string, req Request, o Options) (Result, error)

Reserve performs one act against origin: fetch, judge, write one commit, then one plain push, which is the compare-and-swap. A release pushes the tombstone; every other request reserves, renews or takes over, by what the tip it judged allows. A refusal pushes nothing; a failure leaves nothing locally but an unreferenced commit git's collection removes.

type Snapshot

type Snapshot struct {
	// FetchedAt is when abcd last fetched the reservations here; zero when
	// nothing here stamped a fetch, so the view's age is unknown.
	FetchedAt    time.Time
	Reservations []Reservation
}

Snapshot is the reservations as this checkout last fetched them.

func View

func View(root string, now time.Time) (Snapshot, error)

View reads the reservations from this checkout's disk only, as last fetched: no fetch and no push. Each is judged at now by lease.Judge, after the derived release on origin's default branch as last fetched; nothing is written. It is the "as of last fetch" reader every render shares.

func (Snapshot) AsOf

func (s Snapshot) AsOf(now time.Time) string

AsOf dates the view for a render: how long ago abcd last fetched the reservations here, or that the age is unknown when nothing here stamped a fetch (a view a plain git fetch left).

func (Snapshot) HeldBy

func (s Snapshot) HeldBy(id string, now time.Time) string

HeldBy is how a render names a reservation another copy holds on id at now (a live one, or an unreadable one within its hold), with the view's age; "" when nothing holds it but this copy. It is the board's held-by text.

func (Snapshot) LiveByHolder

func (s Snapshot) LiveByHolder() map[string]int

LiveByHolder counts each person's live reservations, usernames compared without regard to case and named as first listed.

func (Snapshot) Lookup

func (s Snapshot) Lookup(id string) (Reservation, bool)

Lookup is id's reservation in the view, when it holds one.

Jump to

Keyboard shortcuts

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