{"modulePath":"github.com/diffsec/agentmon","version":"v0.0.0-20261111001054-230ac962f687","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package simulation\n\nPackage simulation provides testing and simulation modes for agentmon.\n\n## Functions\n\n```go\nfunc SaveTestFile(path string, tests []PolicyTestCase) error\n```\nSaveTestFile saves test cases to a YAML file.\n\n## Types\n\n```go\ntype Decision string\n```\nDecision represents a policy decision.\n\n```go\nconst (\n\tDecisionAllow    Decision = \"allow\"\n\tDecisionDeny     Decision = \"deny\"\n\tDecisionApprove  Decision = \"approve\"\n\tDecisionRedirect Decision = \"redirect\"\n\tDecisionAudit    Decision = \"audit\"\n)\n```\n\n```go\ntype DecisionLogger interface {\n\tLogDecision(op *Operation, decision Decision, wouldEnforce bool)\n}\n```\nDecisionLogger logs decisions in various modes.\n\n```go\ntype Difference struct {\n\tEvent       RecordedEvent `json:\"event\"`\n\tOldDecision string        `json:\"old_decision\"`\n\tNewDecision string        `json:\"new_decision\"`\n\tOldRule     string        `json:\"old_rule,omitempty\"`\n\tNewRule     string        `json:\"new_rule,omitempty\"`\n}\n```\nDifference describes a decision difference during replay.\n\n```go\ntype DryRunConfig struct {\n\tEnabled      bool `json:\"enabled\" yaml:\"enabled\"`\n\tLogDecisions bool `json:\"log_decisions\" yaml:\"log_decisions\"`\n}\n```\nDryRunConfig configures dry-run mode.\n\n```go\ntype ExpectedResult struct {\n\tDecision   string `yaml:\"decision\" json:\"decision\"`\n\tPolicyRule string `yaml:\"policy_rule,omitempty\" json:\"policy_rule,omitempty\"`\n\tRedirectTo string `yaml:\"redirect_to,omitempty\" json:\"redirect_to,omitempty\"`\n\tMessage    string `yaml:\"message,omitempty\" json:\"message,omitempty\"`\n}\n```\nExpectedResult defines the expected outcome of a test.\n\n```go\ntype Mode string\n```\nMode represents the current operational mode.\n\n```go\nconst (\n\tModeNormal     Mode = \"normal\"\n\tModeDryRun     Mode = \"dry_run\"\n\tModeSimulation Mode = \"simulation\"\n\tModePermissive Mode = \"permissive\"\n\tModeStrict     Mode = \"strict\"\n)\n```\n\n```go\ntype ModeConfig struct {\n\t// DryRun logs what would happen without enforcing\n\tDryRun DryRunConfig `json:\"dry_run\" yaml:\"dry_run\"`\n\n\t// Simulation runs against recorded sessions\n\tSimulation SimulationConfig `json:\"simulation\" yaml:\"simulation\"`\n\n\t// Permissive allows all but logs everything\n\tPermissive PermissiveConfig `json:\"permissive\" yaml:\"permissive\"`\n\n\t// Strict denies by default\n\tStrict StrictConfig `json:\"strict\" yaml:\"strict\"`\n}\n```\nModeConfig defines simulation mode configuration.\n\n```go\nfunc DefaultModeConfig() ModeConfig\n```\nDefaultModeConfig returns sensible defaults.\n\n```go\ntype ModeManager struct {\n\t// contains filtered or unexported fields\n}\n```\nModeManager manages operational modes.\n\n```go\nfunc NewModeManager(config ModeConfig, logger DecisionLogger) *ModeManager\n```\nNewModeManager creates a new mode manager.\n\n```go\nfunc (m *ModeManager) Config() ModeConfig\n```\nConfig returns the current mode configuration.\n\n```go\nfunc (m *ModeManager) CurrentMode() Mode\n```\nCurrentMode returns the current operational mode.\n\n```go\nfunc (m *ModeManager) DefaultDecision() Decision\n```\nDefaultDecision returns the default decision for the current mode.\n\n```go\nfunc (m *ModeManager) IsDryRun() bool\n```\nIsDryRun returns whether dry-run mode is active.\n\n```go\nfunc (m *ModeManager) IsPermissive() bool\n```\nIsPermissive returns whether permissive mode is active.\n\n```go\nfunc (m *ModeManager) IsSimulation() bool\n```\nIsSimulation returns whether simulation mode is active.\n\n```go\nfunc (m *ModeManager) IsStrict() bool\n```\nIsStrict returns whether strict mode is active.\n\n```go\nfunc (m *ModeManager) ProcessDecision(op *Operation, decision Decision) Decision\n```\nProcessDecision processes a decision based on the current mode.\n\n```go\nfunc (m *ModeManager) SetMode(mode Mode)\n```\nSetMode changes the operational mode.\n\n```go\nfunc (m *ModeManager) ShouldEnforce() bool\n```\nShouldEnforce returns whether decisions should be enforced.\n\n```go\nfunc (m *ModeManager) ShouldLog() bool\n```\nShouldLog returns whether decisions should be logged.\n\n```go\ntype Operation struct {\n\tType        string            `json:\"type\"`\n\tPath        string            `json:\"path,omitempty\"`\n\tDomain      string            `json:\"domain,omitempty\"`\n\tVariable    string            `json:\"variable,omitempty\"`\n\tProcessName string            `json:\"process_name,omitempty\"`\n\tMetadata    map[string]string `json:\"metadata,omitempty\"`\n}\n```\nOperation represents an operation being evaluated.\n\n```go\ntype PermissiveConfig struct {\n\tEnabled bool `json:\"enabled\" yaml:\"enabled\"`\n}\n```\nPermissiveConfig configures permissive mode.\n\n```go\ntype PolicyEvaluator interface {\n\tEvaluate(op *Operation) TestResult\n}\n```\nPolicyEvaluator evaluates operations against policies.\n\n```go\ntype PolicyTestCase struct {\n\tName        string         `yaml:\"name\" json:\"name\"`\n\tDescription string         `yaml:\"description,omitempty\" json:\"description,omitempty\"`\n\tOperation   TestOperation  `yaml:\"operation\" json:\"operation\"`\n\tExpected    ExpectedResult `yaml:\"expected\" json:\"expected\"`\n}\n```\nPolicyTestCase represents a single policy test case.\n\n```go\nfunc LoadTestFile(path string) ([]PolicyTestCase, error)\n```\nLoadTestFile loads test cases from a YAML file.\n\n```go\ntype PolicyTestFile struct {\n\tTests []PolicyTestCase `yaml:\"tests\" json:\"tests\"`\n}\n```\nPolicyTestFile represents a file containing test cases.\n\n```go\ntype PolicyTester struct {\n\t// contains filtered or unexported fields\n}\n```\nPolicyTester runs policy tests.\n\n```go\nfunc NewPolicyTester(evaluator PolicyEvaluator) *PolicyTester\n```\nNewPolicyTester creates a new policy tester.\n\n```go\nfunc (p *PolicyTester) RunTestDir(dir string) (*TestResults, error)\n```\nRunTestDir runs all test files in a directory.\n\n```go\nfunc (p *PolicyTester) RunTestFile(path string) (*TestResults, error)\n```\nRunTestFile runs tests from a file.\n\n```go\nfunc (p *PolicyTester) RunTests(tests []PolicyTestCase) *TestResults\n```\nRunTests runs a set of test cases.\n\n```go\ntype RecordedEvent struct {\n\tTimestamp  time.Time       `json:\"ts\"`\n\tType       string          `json:\"type\"`\n\tSessionID  string          `json:\"session_id,omitempty\"`\n\tAgentID    string          `json:\"agent_id,omitempty\"`\n\tRequest    json.RawMessage `json:\"request\"`\n\tDecision   string          `json:\"decision\"`\n\tPolicyRule string          `json:\"policy_rule,omitempty\"`\n\tLatency    time.Duration   `json:\"latency_ns\"`\n}\n```\nRecordedEvent represents a recorded operation event.\n\n```go\nfunc LoadRecording(path string) ([]RecordedEvent, error)\n```\nLoadRecording loads all events from a recording file.\n\n```go\ntype RecorderConfig struct {\n\tSessionID  string\n\tOutputPath string\n\tAppend     bool\n}\n```\nRecorderConfig configures the session recorder.\n\n```go\ntype RecordingStats struct {\n\tEventCount    int            `json:\"event_count\"`\n\tDuration      time.Duration  `json:\"duration\"`\n\tFirstEvent    time.Time      `json:\"first_event\"`\n\tLastEvent     time.Time      `json:\"last_event\"`\n\tEventsByType  map[string]int `json:\"events_by_type\"`\n\tDecisionCount map[string]int `json:\"decisions\"`\n\tSessionID     string         `json:\"session_id,omitempty\"`\n}\n```\nRecordingStats returns statistics about a recording.\n\n```go\nfunc GetRecordingStats(path string) (*RecordingStats, error)\n```\nGetRecordingStats returns statistics about a recording file.\n\n```go\ntype ReplayResults struct {\n\tTotalEvents int          `json:\"total_events\"`\n\tMatched     int          `json:\"matched\"`\n\tDifferences []Difference `json:\"differences,omitempty\"`\n\tErrors      []string     `json:\"errors,omitempty\"`\n}\n```\nReplayResults contains the results of replaying a session.\n\n```go\nfunc (r *ReplayResults) HasDifferences() bool\n```\nHasDifferences returns true if there are any differences.\n\n```go\nfunc (r *ReplayResults) Summary() string\n```\nSummary returns a human-readable summary.\n\n```go\ntype SessionRecorder struct {\n\t// contains filtered or unexported fields\n}\n```\nSessionRecorder records session events to a file.\n\n```go\nfunc NewSessionRecorder(config RecorderConfig) (*SessionRecorder, error)\n```\nNewSessionRecorder creates a new session recorder.\n\n```go\nfunc NewSessionRecorderWriter(sessionID string, w io.WriteCloser) *SessionRecorder\n```\nNewSessionRecorderWriter creates a recorder with a custom writer.\n\n```go\nfunc (r *SessionRecorder) Close() error\n```\nClose closes the recorder.\n\n```go\nfunc (r *SessionRecorder) Duration() time.Duration\n```\nDuration returns the recording duration.\n\n```go\nfunc (r *SessionRecorder) EventCount() int\n```\nEventCount returns the number of recorded events.\n\n```go\nfunc (r *SessionRecorder) Record(op *Operation, decision Decision, policyRule string, latency time.Duration) error\n```\nRecord records an event.\n\n```go\nfunc (r *SessionRecorder) RecordRaw(event RecordedEvent) error\n```\nRecordRaw records a raw event.\n\n```go\ntype SessionReplayer struct {\n\t// contains filtered or unexported fields\n}\n```\nSessionReplayer replays recorded sessions against a policy.\n\n```go\nfunc NewSessionReplayer(recordingPath string, evaluator PolicyEvaluator) *SessionReplayer\n```\nNewSessionReplayer creates a new session replayer.\n\n```go\nfunc (r *SessionReplayer) Replay() (*ReplayResults, error)\n```\nReplay replays the recorded session and compares decisions.\n\n```go\nfunc (r *SessionReplayer) ReplayReader(reader io.Reader) (*ReplayResults, error)\n```\nReplayReader replays from a reader.\n\n```go\ntype SimulationConfig struct {\n\tEnabled    bool   `json:\"enabled\" yaml:\"enabled\"`\n\tReplayFile string `json:\"replay_file\" yaml:\"replay_file\"`\n}\n```\nSimulationConfig configures simulation/replay mode.\n\n```go\ntype StrictConfig struct {\n\tEnabled bool `json:\"enabled\" yaml:\"enabled\"`\n}\n```\nStrictConfig configures strict mode.\n\n```go\ntype TestFailure struct {\n\tTestName    string         `json:\"test_name\"`\n\tDescription string         `json:\"description,omitempty\"`\n\tOperation   TestOperation  `json:\"operation\"`\n\tExpected    ExpectedResult `json:\"expected\"`\n\tGot         TestResult     `json:\"got\"`\n\tError       string         `json:\"error,omitempty\"`\n}\n```\nTestFailure describes a failed test.\n\n```go\ntype TestOperation struct {\n\tType        string            `yaml:\"type\" json:\"type\"`\n\tPath        string            `yaml:\"path,omitempty\" json:\"path,omitempty\"`\n\tDomain      string            `yaml:\"domain,omitempty\" json:\"domain,omitempty\"`\n\tPort        int               `yaml:\"port,omitempty\" json:\"port,omitempty\"`\n\tVariable    string            `yaml:\"variable,omitempty\" json:\"variable,omitempty\"`\n\tCommand     string            `yaml:\"command,omitempty\" json:\"command,omitempty\"`\n\tProcessName string            `yaml:\"process_name,omitempty\" json:\"process_name,omitempty\"`\n\tMetadata    map[string]string `yaml:\"metadata,omitempty\" json:\"metadata,omitempty\"`\n}\n```\nTestOperation defines the operation to test.\n\n```go\nfunc (t *TestOperation) ToOperation() *Operation\n```\nToOperation converts TestOperation to Operation.\n\n```go\ntype TestResult struct {\n\tDecision   string `json:\"decision\"`\n\tPolicyRule string `json:\"policy_rule,omitempty\"`\n\tRedirectTo string `json:\"redirect_to,omitempty\"`\n\tMessage    string `json:\"message,omitempty\"`\n}\n```\nTestResult is the actual result from evaluation.\n\n```go\ntype TestResults struct {\n\tPassed  int           `json:\"passed\"`\n\tFailed  int           `json:\"failed\"`\n\tSkipped int           `json:\"skipped\"`\n\tTotal   int           `json:\"total\"`\n\tErrors  []TestFailure `json:\"errors,omitempty\"`\n}\n```\nTestResults contains the results of running policy tests.\n\n```go\nfunc (r *TestResults) Success() bool\n```\nSuccess returns true if all tests passed.\n\n```go\nfunc (r *TestResults) Summary() string\n```\nSummary returns a human-readable summary of test results.\n\n","path":"github.com/diffsec/agentmon/pkg/simulation","name":"simulation","synopsis":"Package simulation provides testing and simulation modes for agentmon.","isRedistributable":true}
