resetops

package
v0.1.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package resetops implements the machine-wide reset cascade behind `gridctl reset` and POST /api/reset. It composes the kind managers that own every write (skillsync, agentsync, contexts, wiring) plus the daemon/runtime state helpers; like pkg/packops it owns only the orchestration, never a write path of its own.

Removal is lockfile-driven per Constitution Article XVI: only artifacts the projection lockfile or wiring records attest gridctl created are touched, drifted (hand-edited) artifacts are kept unless forced, and foreign entries in shared client configs are never deleted. The cascade order is load-bearing: daemons stop first (a live daemon's reconcile loop re-projects skills into client trees mid-removal), the projection lockfile is consumed last.

Index

Constants

View Source
const (
	ActionWouldRemove = "would-remove"
	ActionWouldStop   = "would-stop"
	ActionRemoved     = "removed"
	ActionStopped     = "stopped"
	ActionKeptDrift   = "kept-drift"
	ActionKeptForeign = "kept-foreign"
	ActionDropRecord  = "dropped-record"
	ActionAlreadyGone = "already-gone"
	ActionFailed      = "failed"
	ActionSkipped     = "skipped"
)

Row actions. Preview uses the would- forms; execution reports what actually happened.

View Source
const SchemaVersion = 1

SchemaVersion versions every reset document (Article X / XVII).

Variables

This section is empty.

Functions

This section is empty.

Types

type Doc

type Doc struct {
	SchemaVersion int         `json:"schema_version"`
	Home          string      `json:"home"`
	Purge         bool        `json:"purge"`
	DryRun        bool        `json:"dry_run"`
	BackupPath    string      `json:"backup_path,omitempty"`
	BackupNote    string      `json:"backup_note,omitempty"`
	Rows          []Row       `json:"rows"`
	Kept          []string    `json:"kept,omitempty"`
	Failed        int         `json:"failed"`
	Stats         *PurgeStats `json:"purge_stats,omitempty"`

	// Finalize is set by Execute when Options.SelfPID deferred the
	// caller's own teardown; run it after the response is flushed.
	// Never serialized.
	Finalize func() error `json:"-"`
}

Doc is the machine-readable reset document: the same shape backs --dry-run, the interactive preview, and the execution result, all computed from one inventory so the preview cannot lie.

type Managers

type Managers struct {
	Skills   skillSyncer
	Agents   agentSyncer
	Contexts contextSyncer
	Wiring   wireManager
	Runtime  Runtime
	Home     string

	// Missing names surfaces whose manager could not be constructed
	// (unreadable registry, unresolvable home for one kind). Each entry
	// becomes a skipped row and a counted failure, so a reset that could
	// not see a surface exits 1 and the user re-runs once it is back. A
	// nil manager with no Missing entry means the surface is simply not
	// configured (tests, minimal embeddings) and stays silent.
	Missing []string
}

Managers bundles everything the reset cascade drives. Construct with the real managers in cmd / internal/api; tests inject fakes.

func (*Managers) Backup

func (m *Managers) Backup(ctx context.Context, doc *Doc, now time.Time) (string, error)

Backup writes the pre-destruction archive for doc and returns its path. Fail-closed: any error here must abort the reset; a partial backup is worse than none. The purge archive lives OUTSIDE the tree being purged, or it would delete itself.

func (*Managers) Execute

func (m *Managers) Execute(ctx context.Context, opts Options, progress Progress) (*Doc, error)

Execute runs the reset cascade: backup, stop daemons, unsync projections, unlink wiring, tear down containers, delete state files, and (purge) remove <home>/.gridctl. Per-item failures are reported in rows and counted, never silently swallowed (Article XI); the pass continues so a re-run removes only the remainder (idempotent retry).

Ordering is load-bearing: daemons die FIRST because a live daemon's registry-refresh reconcile re-projects skills and agents into client trees, racing the removals. The projection lockfile is consumed last, entry by entry, through the managers that own it.

func (*Managers) GridctlDir

func (m *Managers) GridctlDir() string

GridctlDir returns the state directory reset --purge deletes.

func (*Managers) Preview

func (m *Managers) Preview(ctx context.Context, opts Options) (*Doc, error)

Preview computes the reset document without writing anything.

type Options

type Options struct {
	// Purge additionally deletes <home>/.gridctl after the cascade.
	Purge bool
	// Force removes drifted (hand-edited) projections too. Foreign
	// wiring entries are never removed, force or not.
	Force bool
	// SelfPID, when non-zero, defers actions that would kill the calling
	// process: the daemon with this PID is not stopped, its state file
	// is not deleted, and the purge RemoveAll is deferred. Execute then
	// returns a non-nil Finalize on the Doc; the caller runs it after
	// its HTTP response is flushed (see FR12a self-termination).
	SelfPID int
}

Options configure a reset pass.

type Progress

type Progress func(phase string, row *Row)

Progress streams execution to the caller: a phase transition (row == nil) or one completed row. Never called concurrently.

type PurgeStats

type PurgeStats struct {
	GridctlDir     string `json:"gridctl_dir"`
	VaultVariables int    `json:"vault_variables"`
	OAuthServers   int    `json:"oauth_servers"`
	PinFiles       int    `json:"pin_files"`
	TelemetryBytes int64  `json:"telemetry_bytes"`
}

PurgeStats enumerates what --purge destroys beyond the cascade, so the confirmation can show real numbers. Counts of -1 render as "unknown" (e.g. a locked vault).

type Row

type Row struct {
	Kind   string `json:"kind"` // skill | agent | context | wiring | daemon | containers | state-file | gridctl-dir
	Name   string `json:"name"`
	Client string `json:"client,omitempty"`
	Path   string `json:"path,omitempty"`
	Action string `json:"action"`
	Detail string `json:"detail,omitempty"`
	Error  string `json:"error,omitempty"`
}

Row is one artifact line in reset output.

type Runtime

type Runtime interface {
	Down(ctx context.Context, stackName string) error
}

Runtime is the container-teardown slice of pkg/runtime. Nil in Managers means container cleanup is skipped with a reported row (e.g. Docker unavailable).

Jump to

Keyboard shortcuts

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