Files
SWOOSH/state.go
2025-10-24 18:35:13 +11:00

124 lines
3.1 KiB
Go

package swoosh
import "time"
// CouncilMember represents one elected or proposed council participant.
// This struct must be stable across replicas and serialization order.
type CouncilMember struct {
ID string `json:"id"`
Role string `json:"role"`
PublicKey string `json:"public_key"`
VoteWeight int `json:"vote_weight"`
Signatures []string `json:"signatures"`
Status string `json:"status"`
Epoch uint64 `json:"epoch"`
}
// EnvResource defines one environment allocation or provisioned asset.
// It is used by the Environment phase to track compute or service resources.
type EnvResource struct {
ID string `json:"id"`
Type string `json:"type"`
Address string `json:"address"`
Capacity string `json:"capacity"`
AllocatedAt time.Time `json:"allocated_at"`
ReleasedAt time.Time `json:"released_at"`
HealthStatus string `json:"health_status"`
Provider string `json:"provider"`
}
// OrchestratorState captures the full replicated SWOOSH state machine.
type OrchestratorState struct {
Meta struct {
Version string
SchemaHash string
}
Boot struct {
Licensed bool
LicenseExpiry time.Time
NodeID string
}
Ingestion struct {
Phase string
ContentHash string
SourceSet []string
LastError string
Epoch uint64
}
Council struct {
Phase string
PlannedRoles []string
Members []CouncilMember
QuorumCertHash string
MCPHealthGreen bool
Epoch uint64
}
Environment struct {
Phase string
CapacityOK bool
Health string
Resources []EnvResource
Epoch uint64
}
Execution struct {
Phase string
ActiveWindowID string
BeatIndex uint64
PlanLocked bool
Approvals uint32
Epoch uint64
}
Control struct {
Paused bool
Degraded bool
Recovering bool
}
Policy struct {
Quarantined bool
Rationale string
}
HLCLast string
StateHash string
}
// TransitionProposal encapsulates a requested state transition.
type TransitionProposal struct {
CurrentStateHash string `json:"current_state_hash"`
TransitionName string `json:"transition"`
InputsHash string `json:"inputs_hash"`
Signer string `json:"signer"`
IdemKey string `json:"idem_key"`
HLC string `json:"hlc"`
WindowID string `json:"window_id"`
Evidence []string `json:"evidence"`
}
// GuardOutcome aggregates guard evaluation for a transition.
type GuardOutcome struct {
LicenseOK bool
BackbeatOK bool
QuorumOK bool
PolicyOK bool
MCPHealthy bool
Rationale []string
}
// WALRecord captures append-only transition metadata for replay and audit.
type WALRecord struct {
StatePreHash string `json:"state_pre_hash"`
StatePostHash string `json:"state_post_hash"`
Transition TransitionProposal `json:"transition"`
Guard GuardOutcome `json:"guard"`
AppliedAtHLC string `json:"applied_hlc"`
AppliedAtUnixNs int64 `json:"applied_unix_ns"`
Index uint64 `json:"index"`
}