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
- Variables
- func GitHead(ctx context.Context, repo string) (string, error)
- func IsCriticalPath(p string) bool
- func PatchTouchedPaths(patch []byte) []string
- func ProducerAdmitted(mode, producer string, pub ed25519.PublicKey) bool
- func ProducerID(pub ed25519.PublicKey) string
- func ProducerMode(mode string) string
- func SameRef(ctx context.Context, repo, ref, head string) bool
- func TouchesCritical(dir string, files []string) (bool, []string, error)
- type Check
- type GateDigest
- type GateLeg
- type Manager
- func (m *Manager) AcquireWorktreeLock(ctx context.Context) (func(), error)
- func (m *Manager) Apply(ctx context.Context, id string) error
- func (m *Manager) ApplyLocked(ctx context.Context, id string) error
- func (m *Manager) Archive(id string, state SetState) error
- func (m *Manager) ClearConflicted(id string) error
- func (m *Manager) Doctor(ctx context.Context) []Check
- func (m *Manager) EnsureWorktree(ctx context.Context) error
- func (m *Manager) Get(id string) (Set, error)
- func (m *Manager) Import(src string) (Set, error)
- func (m *Manager) LockPath() string
- func (m *Manager) MarkConflicted(id string) error
- func (m *Manager) MarkRejected(id string) error
- func (m *Manager) MarkState(id string, state SetState) error
- func (m *Manager) Mint(ctx context.Context, baseRef, title, version string, pub ed25519.PublicKey, ...) (Set, error)
- func (m *Manager) NextVersion(base string) string
- func (m *Manager) NoteVersionUsed(version string) error
- func (m *Manager) Queue() ([]Set, error)
- func (m *Manager) RebaseOnto(ctx context.Context, id, newBase string, pub ed25519.PublicKey, ...) error
- func (m *Manager) Repo() string
- func (m *Manager) Reset(ctx context.Context, purgeQueue bool) error
- func (m *Manager) Root() string
- func (m *Manager) StageTree(ctx context.Context, wt, dst, version string) error
- func (m *Manager) WorktreePath() string
- type Manifest
- type Set
- type SetState
Constants ¶
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).
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 ¶
var CriticalPathPrefixes = []string{
"internal/updater/",
"internal/security/",
"internal/trust/",
"internal/defense/",
"internal/bus/",
"internal/storage/",
"internal/self/",
"adapters/",
"extensions/",
"drivers/",
"tests/",
"cmd/",
"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.
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.
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 IsCriticalPath ¶
IsCriticalPath reports whether p sits under a critical prefix.
func PatchTouchedPaths ¶
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 ¶
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 ¶
ProducerID is the stable "k:<pub>" identity a producer's sets carry.
func ProducerMode ¶
ProducerMode normalizes the configured producers value: the empty string means "self" (the documented default).
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.
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 ¶
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 ¶
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 ¶
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 ¶
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) ClearConflicted ¶
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 ¶
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 ¶
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) Import ¶
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 ¶
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 ¶
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 ¶
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) 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 ¶
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 ¶
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) 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) Reset ¶
Reset removes the worktree and (optionally) every queued/archived set — the `panda self reset` escape hatch back to "no self-evolution state".
func (*Manager) StageTree ¶
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 ¶
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 ¶
LoadManifest reads and fully validates a manifest.json in dir: structure, signature self-consistency, and that every listed patch file exists.
func (Manifest) Digest ¶
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 ¶
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 ¶
Validate checks the manifest's structural sanity (independent of signature).
func (Manifest) VerifySignature ¶
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).