self

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: AGPL-3.0 Imports: 21 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 self is the self-evolution pipeline's local machinery: signed patch-set manifests, the on-disk queue under <data>/self/, the git worktree the patch sets merge into, and the release-equivalent gate runner. Everything here is opt-in — nothing in this package runs unless the operator enabled self_evolution, minted or imported a patch set, and approved its merge through the task-review gate.

Index

Constants

View Source
const (
	// ProducersSelf admits only sets signed by this node's own key.
	ProducersSelf = "self"
	// ProducersMesh admits any signer — the mesh-wide policy.
	ProducersMesh = "mesh"
)

ProducersSelf and ProducersMesh are the two admission policies a node can run under (config: self_evolution.producers).

View Source
const ManifestKind = "openpanda-patchset/1"

ManifestKind is the only accepted `kind` value — the format version travels inside the tag so a future v2 cannot be parsed by v1 nodes.

Variables

View Source
var CriticalPathPrefixes = []string{
	"internal/updater/",
	"internal/security/",
	"internal/trust/",
	"internal/defense/",
	"internal/bus/",
	"internal/storage/",

	"internal/self/",
	"Makefile",
	"go.mod", "go.sum",
	".github/",
	"scripts/package.sh", "scripts/sign",
}

CriticalPathPrefixes are the trees a patch set must flag before it may be merged — the parts of the system whose self-modification carries the most risk: the update/verify machinery itself, the trust and defense layers, the wire codec, storage migrations, and the gate definition.

View Source
var ErrWorktreeBusy = errors.New("self-evolution worktree is busy")

ErrWorktreeBusy reports that another process/goroutine holds the worktree lock. Callers should skip rather than mark a patch set conflicted: the set is fine, the worktree is merely occupied.

View Source
var GateLegs = []string{
	"fmt-check",
	"vet",
	"staticcheck",
	"build",
	"adapter-test",
	"test",
	"race-focused",
}

GateLegs is the release gate spelled out as the Makefile's `gate` target runs it — seven legs, each invoked through make so the Makefile stays the single definition of what "release-equivalent" means. A patch set that cannot pass all seven is not mergeable.

Functions

func GitHead

func GitHead(ctx context.Context, repo string) (string, error)

GitHead resolves repo's HEAD commit — the base a rebase sweep targets.

func IsCriticalPath

func IsCriticalPath(p string) bool

IsCriticalPath reports whether p sits under a critical prefix.

func PatchTouchedPaths

func PatchTouchedPaths(patch []byte) []string

PatchTouchedPaths extracts the file paths a unified diff touches. It reads BOTH the `diff --git a/… b/…` header and `+++ b/…` lines: relying on `+++` alone misses deletions (`+++ /dev/null`), pure renames (no +++ line), and anything git quotes because the path carries spaces or non-ASCII bytes.

func ProducerAdmitted

func ProducerAdmitted(mode, producer string, pub ed25519.PublicKey) bool

ProducerAdmitted reports whether a set signed by producer may enter this node's merge queue under the given producers mode.

The rule lives here, not in its callers: the boot-time rebase sweep, the propose path and the operator's `panda self rebase` must agree. Any path that re-signs a set with the node's own key would otherwise turn a foreign set — which propose refuses — into a locally signed, mergeable one.

func ProducerID

func ProducerID(pub ed25519.PublicKey) string

ProducerID is the stable "k:<pub>" identity a producer's sets carry.

func ProducerMode

func ProducerMode(mode string) string

ProducerMode normalizes the configured producers value: the empty string means "self" (the documented default).

func SameRef

func SameRef(ctx context.Context, repo, ref, head string) bool

SameRef reports whether ref and head resolve to the same commit in repo — a patch set minted against a tag/branch name stays current while that ref still points at the same sha.

func TouchesCritical

func TouchesCritical(dir string, files []string) (bool, []string, error)

TouchesCritical recomputes the critical flag from the patch bodies on disk — the merge-side check never trusts the manifest's claim.

Types

type Check

type Check struct {
	Name string `json:"name"`
	OK   bool   `json:"ok"`
	Note string `json:"note,omitempty"`
}

Check is one doctor finding. OK=false on a required item means the self-evolution pipeline cannot run on this node; a warn-only item (OK=true, Note set) is a real cost or partial capability the operator should know.

type GateDigest

type GateDigest struct {
	OK    bool      `json:"ok"`
	At    int64     `json:"at"`
	Legs  []GateLeg `json:"legs"`
	Maker string    `json:"maker"` // go version string, ties the digest to a toolchain
}

GateDigest summarizes the producer-side `make gate` run.

func RunGate

func RunGate(ctx context.Context, dir string) GateDigest

RunGate executes the release gate inside dir (normally the merge worktree) leg by leg, stopping at the first failure — the digest records how far the set got, which is the reviewer's fastest signal for "what broke".

type GateLeg

type GateLeg struct {
	Name string `json:"name"`
	OK   bool   `json:"ok"`
	Sec  int64  `json:"sec"`
	Tail string `json:"tail,omitempty"` // last lines when the leg failed
}

GateLeg is one leg of the release gate's outcome on the PRODUCING node. The digest is evidence, not authority: the merge-side gate re-runs the real thing, but the digest lets a reviewer see what the producer claims passed and lets the mesh distrust a set that never saw a gate at all.

type Manager

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

Manager owns the <data>/self/ tree. All state lives under it so `panda self reset` is a directory removal and nothing outside the node knows it exists.

root/
  worktree/          git worktree of the project checkout (created lazily)
  queue/<id>/        manifest.json + *.patch awaiting review
  archive/<id>/      terminal sets (merged/rejected/conflicted)

func New

func New(root, repo string, logger *slog.Logger) *Manager

New returns a Manager over root. repo may be empty — worktree operations then fail with a clear error while queue inspection still works.

func (*Manager) AcquireWorktreeLock

func (m *Manager) AcquireWorktreeLock(ctx context.Context) (func(), error)

AcquireWorktreeLock serializes every operation that touches the merge worktree — apply, rebase, mint and reset — across processes (the daemon and a `panda approve`/`panda self` CLI share the same state root). It fails rather than blocking: a busy worktree is an operator-visible condition.

func (*Manager) Apply

func (m *Manager) Apply(ctx context.Context, id string) error

Apply applies a queued set's patches to the worktree in manifest order. The worktree is reset hard to the manifest's base first: each set lands on a clean, declared foundation, never on top of a previous set's leftovers.

func (*Manager) ApplyLocked

func (m *Manager) ApplyLocked(ctx context.Context, id string) error

ApplyLocked is Apply for a caller that already holds the worktree lock — the merge pipeline holds it across apply→gate→build→swap, so its Apply must not deadlock on a second acquisition.

func (*Manager) Archive

func (m *Manager) Archive(id string, state SetState) error

Archive moves a queued set into archive/ with a terminal state marker.

func (*Manager) ClearConflicted

func (m *Manager) ClearConflicted(id string) error

ClearConflicted lifts the marker after a successful rebase — a set that was never conflicted has nothing to lift.

Only a CONFLICTED marker is lifted. A rejected or merged marker is the human's verdict (or the merge's own record); erasing it would put a terminal set back into the proposable queue.

func (*Manager) Doctor

func (m *Manager) Doctor(ctx context.Context) []Check

Doctor runs the toolchain preflight (design §5.1): the gate's footprint is developer-grade — go, git, python3 for the adapter contract, a C toolchain for the CGO race leg, and network on the first staticcheck fetch. The point of the report is to answer "can this node self-evolve" before a proposal burns a review on a machine that was never going to merge.

func (*Manager) EnsureWorktree

func (m *Manager) EnsureWorktree(ctx context.Context) error

EnsureWorktree creates the merge worktree on first use: a detached git worktree of the configured repo. It refuses to reuse a directory that is not a worktree of the right repo — the merge pipeline's blast radius must be provably contained.

func (*Manager) Get

func (m *Manager) Get(id string) (Set, error)

Get resolves one set by id across queue and archive.

func (*Manager) Import

func (m *Manager) Import(src string) (Set, error)

Import copies a patch-set directory into the queue after full validation — the entry point for sets minted elsewhere (mesh transfer lands here in P5) or by an agent task on this node.

func (*Manager) LockPath

func (m *Manager) LockPath() string

LockPath is the cross-process worktree lock. It lives beside the worktree so `panda self reset` removes it with the rest of the state.

func (*Manager) MarkConflicted

func (m *Manager) MarkConflicted(id string) error

MarkConflicted flags a queued set whose rebase or merge failed — it stays visible in the queue (the operator decides: rebase it, or reject it to the archive) but can never be proposed for merge while marked.

func (*Manager) MarkRejected

func (m *Manager) MarkRejected(id string) error

MarkRejected retires a queued set in place. It is the fallback when moving the directory into archive/ fails: without a marker the rejected set would stay proposable, as if the human had never said no.

func (*Manager) MarkState

func (m *Manager) MarkState(id string, state SetState) error

MarkState writes the one-word state marker a queued set carries.

func (*Manager) Mint

func (m *Manager) Mint(ctx context.Context, baseRef, title, version string, pub ed25519.PublicKey, priv ed25519.PrivateKey, gate GateDigest) (Set, error)

Mint assembles a patch set from the worktree's diff against baseRef, signs it with the node key, and queues it — the producing half of the pipeline.

func (*Manager) NextVersion

func (m *Manager) NextVersion(base string) string

NextVersion derives the target stamp for a fresh patch set: the base release version plus a +self.<n> build counter, where n counts this node's already-merged sets + 1. CompareVersion ignores +meta, so the stamp sorts on its base release and an official update still surfaces as available.

The counter never moves backwards: the merged-set count alone would restart at 1 after `panda self reset --purge` and hand out a stamp older than the binary already installed, so the highest counter ever issued is remembered on disk.

func (*Manager) NoteVersionUsed

func (m *Manager) NoteVersionUsed(version string) error

NoteVersionUsed remembers the counter a built binary was stamped with, so the next stamp is strictly newer than the last one handed out. The caller must treat a failure as fatal to the merge: a stamp that was not persisted can be handed out again after a purge.

func (*Manager) Queue

func (m *Manager) Queue() ([]Set, error)

Queue lists every patch set in queue/ and archive/, newest first.

func (*Manager) RebaseOnto

func (m *Manager) RebaseOnto(ctx context.Context, id, newBase string, pub ed25519.PublicKey, priv ed25519.PrivateKey) error

RebaseOnto rewrites a queued set onto a new base (design §7 q3): apply onto the new base, regenerate the diff, re-mint the manifest with the SAME id and producer signature preserved is impossible — the local node re-signs the rebased set with its own key and notes the origin in the title. This node's approval gate then sees exactly one signer to judge: the re-baser.

func (*Manager) Repo

func (m *Manager) Repo() string

Repo reports the configured project checkout.

func (*Manager) Reset

func (m *Manager) Reset(ctx context.Context, purgeQueue bool) error

Reset removes the worktree and (optionally) every queued/archived set — the `panda self reset` escape hatch back to "no self-evolution state".

func (*Manager) Root

func (m *Manager) Root() string

Root reports where this manager's state lives.

func (*Manager) StageTree

func (m *Manager) StageTree(ctx context.Context, wt, dst, version string) error

StageTree builds a staged-release-shaped tree from the worktree at wt: {dst}/bin/panda plus the adapters/ and extensions/voice/ resource dirs the apply step syncs. The binary is stamped with the patch set's version and Provenance=self so `panda version`, the wire provenance, and the trust layer all see the build for what it is — a locally produced artifact, never a signed release — and which self build is running survives the swap.

func (*Manager) WorktreePath

func (m *Manager) WorktreePath() string

WorktreePath is where the merge worktree lives.

type Manifest

type Manifest struct {
	Kind     string   `json:"kind"`  // ManifestKind
	ID       string   `json:"id"`    // patch-set id, directory name under self/queue/
	Base     string   `json:"base"`  // git ref/commit the patches were produced against
	Version  string   `json:"ver"`   // target version stamp, e.g. 0.0.12-preview+self.3
	Producer string   `json:"prod"`  // k:<ed25519-pub> stable id of the producing node
	Title    string   `json:"title"` // human summary, shown in review
	Files    []string `json:"files"` // patch file names, applied in order
	// Digests binds each patch file's bytes to the signature: without it a
	// patch could be edited after signing and the manifest would still verify.
	// Go marshals string-keyed maps in sorted order, so canonicalBytes stays
	// deterministic.
	Digests map[string]string `json:"digests"`
	Gate    GateDigest        `json:"gate"`
	// TouchesCritical is the PRODUCER's claim; merge re-derives it from the
	// actual patches (TouchesCritical). A set that claims false but touches a
	// critical path is a red flag, not an error — the recomputed bit wins.
	TouchesCritical bool   `json:"critical"`
	Sig             string `json:"sig,omitempty"` // ed25519 hex over canonical manifest minus sig
}

Manifest is openpanda-patchset/1: a signed declaration of what a patch set is, where it applies, and who produced it.

func LoadManifest

func LoadManifest(dir string) (Manifest, error)

LoadManifest reads and fully validates a manifest.json in dir: structure, signature self-consistency, and that every listed patch file exists.

func (Manifest) Digest

func (m Manifest) Digest() string

Digest identifies the exact set a reviewer approved: the sha256 over the canonical manifest (the signature payload). A rebase rewrites the manifest, so the digest moves with it — a proposal can therefore detect that the artifact on disk is no longer the one that was reviewed.

func (Manifest) ProducerPub

func (m Manifest) ProducerPub() (ed25519.PublicKey, error)

ProducerPub returns the producer's Ed25519 key decoded from the manifest's k:<pub> id, so signature verification never depends on a directory lookup.

func (*Manifest) Sign

func (m *Manifest) Sign(priv ed25519.PrivateKey)

Sign attaches the producing node's Ed25519 signature.

func (Manifest) Validate

func (m Manifest) Validate() error

Validate checks the manifest's structural sanity (independent of signature).

func (Manifest) VerifySignature

func (m Manifest) VerifySignature() error

VerifySignature checks the manifest's self-consistency: the signature must verify under the key the Producer id claims. Callers deciding whether THAT producer is trusted use the trust layer — this only proves the manifest was minted by the holder of its own claimed key.

type Set

type Set struct {
	Manifest Manifest
	Dir      string // queue/<id>/ or archive/<id>/
	State    SetState
	// Critical is the RECOMPUTED flag — never the manifest's claim.
	Critical      bool
	CriticalPaths []string
}

Set is one patch set on disk: its manifest plus where it sits.

type SetState

type SetState string

SetState is the patch-set lifecycle, derived from which directory the set lives in plus an optional marker file: queue/ holds sets awaiting (or mid-) review, archive/ holds terminal sets. A "conflicted" marker inside a queue dir marks a set whose rebase onto a newer base failed (design §7 q3).

const (
	StatePending    SetState = "pending"
	StateMerged     SetState = "merged"
	StateRejected   SetState = "rejected"
	StateConflicted SetState = "conflicted"
)

Jump to

Keyboard shortcuts

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