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 ¶
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.
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 ¶
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 ¶
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 ¶
GridctlDir returns the state directory reset --purge deletes.
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 ¶
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.