sim

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package sim provides deterministic, non-privileged acceptance scenarios.

Index

Constants

View Source
const (
	ScenarioSchemaVersion = "antiflock.simulation/v1"
	CoffeeShopScenarioID  = "coffee-shop-route-loss-and-recovery"
)

Variables

This section is empty.

Functions

func RunLiveStream

func RunLiveStream(ctx context.Context, config LiveConfig, interval time.Duration, emit func(LiveStreamEvent) error) error

RunLiveStream bootstraps the simulator and continuously refreshes an explicit simulation-only protected baseline plus signed DETECTED heartbeats. This keeps the developer dashboard useful without claiming anything about the host. Transient refresh failures are reported as safe status records and retried; enrollment or identity failures remain fatal.

Types

type AuditStep

type AuditStep struct {
	Sequence         uint64   `json:"sequence"`
	OccurredAt       string   `json:"occurredAt"`
	Kind             string   `json:"kind"`
	ProtectionState  string   `json:"protectionState,omitempty"`
	EnforcementState string   `json:"enforcementState,omitempty"`
	ActionDecision   string   `json:"actionDecision,omitempty"`
	ReasonCodes      []string `json:"reasonCodes,omitempty"`
	EvidenceClass    string   `json:"evidenceClass"`
	SafeDescription  string   `json:"safeDescription"`
	PreviousHash     string   `json:"previousHash,omitempty"`
	EntryHash        string   `json:"entryHash"`
}

AuditStep is a simulation-only, hash-chained audit projection. EvidenceClass remains explicit so a local detection cannot be mistaken for VERIFIED proof.

type LiveCoffeeShopResult

type LiveCoffeeShopResult struct {
	SchemaVersion        string   `json:"schemaVersion"`
	Simulation           bool     `json:"simulation"`
	NodeID               string   `json:"nodeId"`
	DeploymentID         string   `json:"deploymentId"`
	ActionID             string   `json:"actionId"`
	InitialDecision      string   `json:"initialDecision"`
	FinalDecision        string   `json:"finalDecision"`
	ContextEventIDs      []string `json:"contextEventIds"`
	VerificationEventIDs []string `json:"verificationEventIds"`
	AuditEventIDs        []string `json:"auditEventIds"`
	EvidenceProvenance   string   `json:"evidenceProvenance"`
	IdempotentReplays    int      `json:"idempotentReplays"`
	ChangedReplayRejects int      `json:"changedReplayRejects"`
	StartReplayRejected  bool     `json:"startReplayRejected"`
	Verified             bool     `json:"verified"`
}

LiveCoffeeShopResult is returned only after the live Core flow completes. Verified means the caller requested verification and every durable readback plus fail-closed audit replay semantics succeeded.

func RunLiveCoffeeShop

func RunLiveCoffeeShop(ctx context.Context, config LiveConfig, verify bool) (*LiveCoffeeShopResult, error)

RunLiveCoffeeShop performs a real Core-backed demo. VERIFIED records describe only deterministic simulated facts and are labeled as such; no host network or tunnel state is claimed. When verify is true, success requires durable event/action/posture readback plus idempotent non-start replay, rejected execution-start replay, and changed-content conflict probes.

type LiveConfig

type LiveConfig struct {
	CoreURL        string           `json:"coreUrl,omitempty"`
	OperatorToken  string           `json:"-"`
	AgentToken     string           `json:"-"`
	SDKToken       string           `json:"-"`
	NodeID         string           `json:"nodeId,omitempty"`
	ApplicationID  string           `json:"applicationId,omitempty"`
	StateDirectory string           `json:"stateDirectory,omitempty"`
	BootID         string           `json:"bootId,omitempty"`
	DemoMode       bool             `json:"demoMode,omitempty"`
	Clock          func() time.Time `json:"-"`
}

LiveConfig contains the non-interactive simulator connection contract. Tokens must come from the environment or mounted files; the CLI deliberately has no credential flags so secrets cannot leak through process listings.

type LiveStreamEvent

type LiveStreamEvent struct {
	SchemaVersion string `json:"schemaVersion"`
	Status        string `json:"status"`
	NodeID        string `json:"nodeId"`
	DeploymentID  string `json:"deploymentId,omitempty"`
	EventID       string `json:"eventId,omitempty"`
	ObservedAt    string `json:"observedAt"`
	SafeError     string `json:"safeError,omitempty"`
}

LiveStreamEvent is a non-secret JSON-line status emitted by stream mode.

type Result

type Result struct {
	SchemaVersion        string      `json:"schemaVersion"`
	ScenarioID           string      `json:"scenarioId"`
	Simulation           bool        `json:"simulation"`
	StartedAt            string      `json:"startedAt"`
	NodeID               string      `json:"nodeId"`
	PolicyID             string      `json:"policyId"`
	PolicyRevision       uint64      `json:"policyRevision"`
	Timeline             []AuditStep `json:"timeline"`
	FinalProtectionState string      `json:"finalProtectionState"`
	FinalActionDecision  string      `json:"finalActionDecision"`
	AuditRoot            string      `json:"auditRoot"`
}

func RunCoffeeShop

func RunCoffeeShop(start time.Time) (*Result, error)

RunCoffeeShop evaluates the locked route-loss, action-hold, recovery, and release flow using the real deterministic posture and action-gate code. It performs no network calls or host mutation.

func (*Result) Validate

func (result *Result) Validate() error

Jump to

Keyboard shortcuts

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