rescue

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 12 Imported by: ? 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 rescue is the cross-overmind stranded-worker rescue channel: a flock-guarded JSON queue file. Fleet overminds enqueue quarantined workers; the assist overmind's workers claim and complete rescues; fleet overminds relaunch workers whose record is done. Operators edit the same file for manual rescues. Spec: docs/superpowers/specs/2026-07-03-stranded-worker-quarantine-design.md

Index

Constants

View Source
const (
	FuelPerJump  = 5
	FuelBuffer   = 5
	FuelMin      = 10
	FuelFallback = 25
)

Rescue-fuel sizing (spec: 5 per jump to the nearest station + one jump's slack for the intra-system leg; floor 10; fallback when routing fails).

Variables

This section is empty.

Functions

func AppendDebt

func AppendDebt(agentsDir, strandeeID string, d Debt) error

AppendDebt adds one debt to the strandee's list, creating the file if absent.

func FuelForSystem

func FuelForSystem(ctx context.Context, kb knowledge.Base, systemID string) (int, error)

FuelForSystem sizes the rescue transfer for a strandee in systemID: BFS to the nearest station-bearing system, then fuelForHops. On any routing failure the caller should fall back to FuelFallback.

func RemoveHead

func RemoveHead(agentsDir, strandeeID string) error

RemoveHead drops the first debt and rewrites the file (removing it when the list empties). A missing/empty file is a no-op.

func ResolveSystemID

func ResolveSystemID(systems []knowledge.System, nameOrID string) (string, bool)

ResolveSystemID maps a system display name (what worker heartbeats carry, e.g. "First Step") or an id to the KB system id. Exact id match wins; otherwise a case-insensitive name match.

func ResolveUsername

func ResolveUsername(agentsDir, agentID string) (string, error)

ResolveUsername reads the agent's in-game username from <agentsDir>/<agentID>/credentials.json. In-game usernames differ from the on-disk agent aliases; refuel --target needs the in-game one.

func TransferQuantity

func TransferQuantity(strandeeMaxFuel, strandeeFuel, rescuerFuel, hopsHome int) int

TransferQuantity sizes a rescue fuel transfer at refuel time: fill the strandee's remaining tank capacity, but never give away more than the rescuer can spare after reserving fuel to fly home (hopsHome jumps at FuelPerJump each, plus FuelBuffer). Both terms clamp at zero, so a rescuer that cannot cover its own trip home returns 0 — the caller then declines the transfer rather than stranding itself.

Types

type Debt

type Debt struct {
	Recipient string `json:"recipient"`
	Credits   int    `json:"credits"`
}

Debt is one owed rescue-fee reimbursement: the strandee gifts Credits to the rescuer's in-game username Recipient once it is next docked.

func LoadDebts

func LoadDebts(agentsDir, strandeeID string) ([]Debt, error)

LoadDebts reads a strandee's outstanding rescue debts. A missing file is not an error — it means no debts.

type Queue

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

Queue is a handle on the shared queue file. Safe for concurrent use across processes: every operation takes an exclusive flock on a sidecar lock file (never renamed, so the lock identity is stable), then atomically rewrites the queue via temp+rename.

func NewQueue

func NewQueue(path string) *Queue

NewQueue returns a queue handle on path. The file need not exist yet.

func (*Queue) Enqueue

func (q *Queue) Enqueue(rec Record) (bool, error)

Enqueue appends rec (status pending, timestamps stamped) unless the agent already has a record of any status — one record per agent, so re-detection while a rescue is in flight is a no-op.

func (*Queue) List

func (q *Queue) List() ([]Record, error)

List returns all records. A missing file is an empty queue; a corrupt file is an error (callers log and skip the tick rather than clobbering it).

func (*Queue) Remove

func (q *Queue) Remove(agentID string) (*Record, error)

Remove deletes the agent's record and returns it (nil if absent).

func (*Queue) Transition

func (q *Queue) Transition(agentID string, from, to Status, mutate func(*Record)) (bool, error)

Transition moves the agent's record from → to (compare-and-set; false when the record is absent or not in from), applying mutate to the record first.

type Record

type Record struct {
	AgentID        string  `json:"agent_id"`
	TargetUsername string  `json:"target_username"`
	Fleet          string  `json:"fleet"`
	System         string  `json:"system"`
	SystemID       string  `json:"system_id"`
	POI            string  `json:"poi"`
	Fuel           float64 `json:"fuel"`
	MaxFuel        float64 `json:"max_fuel"`
	RescueFuel     int     `json:"rescue_fuel"`
	Reason         string  `json:"reason"`
	Status         Status  `json:"status"`
	ClaimedBy      string  `json:"claimed_by"`
	Error          string  `json:"error,omitempty"`
	RequestedAt    string  `json:"requested_at"`
	UpdatedAt      string  `json:"updated_at"`
}

Record is one stranded worker awaiting (or through) rescue.

type Status

type Status string

Status is a rescue record's lifecycle state.

const (
	StatusPending Status = "pending"
	StatusClaimed Status = "claimed"
	StatusDone    Status = "done"
	StatusFailed  Status = "failed"
)

Lifecycle: pending → claimed → done | failed. done triggers rejoin; failed waits for the operator.

Jump to

Keyboard shortcuts

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