policy

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

@index Automatic postprocess policy state, decision logic, and persistence.

Index

Constants

View Source
const (
	PolicyDegraded   = "degraded"
	PolicyFailClosed = "fail_closed"

	SourceAuto     = "auto"
	SourceExplicit = "explicit"
	SourceReset    = "reset"

	StatusOK       = "ok"
	StatusDegraded = "degraded"

	ToolBuildOrUpdateGraph = "build_or_update_graph"
	ToolRunPostprocess     = "run_postprocess"

	DefaultRunLogRetention = 200
	DefaultStatusLimit     = 5
)

Variables

This section is empty.

Functions

func ValidTool

func ValidTool(tool string) bool

ValidTool reports whether a tool participates in automatic postprocess policy tracking. @intent reject arbitrary tool names before they can create inconsistent policy rows.

Types

type DecisionInput

type DecisionInput struct {
	Tool           string
	ExplicitPolicy string
}

@intent carry the inputs that influence automatic postprocess policy resolution.

type Engine

type Engine struct{}

@intent resolve effective postprocess policy from explicit input plus stored failure history.

func (*Engine) Resolve

func (e *Engine) Resolve(ctx context.Context, store *Store, input DecisionInput) (string, string, error)

Resolve selects the effective postprocess policy for the current namespace and tool. @intent default to degraded execution while escalating to fail_closed after repeated recent failures.

type RunRecord

type RunRecord struct {
	Tool         string
	Policy       string
	Source       string
	Status       string
	FailedSteps  []string
	SkippedSteps []string
	CreatedAt    time.Time
}

@intent capture the outcome and policy metadata of one postprocess execution.

type RunSnapshot

type RunSnapshot struct {
	Namespace    string    `json:"namespace"`
	Tool         string    `json:"tool"`
	Policy       string    `json:"policy"`
	Source       string    `json:"source"`
	Status       string    `json:"status"`
	FailedSteps  []string  `json:"failed_steps"`
	SkippedSteps []string  `json:"skipped_steps"`
	CreatedAt    time.Time `json:"created_at"`
}

@intent describe one recorded postprocess run for status and failure inspection.

type StateSnapshot

type StateSnapshot struct {
	Namespace           string    `json:"namespace"`
	Tool                string    `json:"tool"`
	Policy              string    `json:"policy"`
	UpdatedAt           time.Time `json:"updated_at"`
	ConsecutiveFailures int       `json:"consecutive_failures"`
}

@intent expose the latest persisted automatic policy state for one namespace and tool.

type StatusOptions

type StatusOptions struct {
	Namespace   string
	Tool        string
	RecentLimit int
}

@intent scope policy status queries by namespace, tool, and recent-run history length.

type StatusSummary

type StatusSummary struct {
	Status         string          `json:"status"`
	FailClosed     []StateSnapshot `json:"fail_closed,omitempty"`
	RecentFailures []RunSnapshot   `json:"recent_failures,omitempty"`
}

@intent bundle fail-closed state and recent failures into one operator-facing policy summary.

type Store

type Store struct {
	// contains filtered or unexported fields
}

@intent persist and query namespace-scoped postprocess policy state and run history.

func NewStore

func NewStore(db *gorm.DB) *Store

NewStore creates a persistence helper for postprocess policy state and run logs. @intent keep policy decisions and failure streaks queryable across build and postprocess executions.

func (*Store) ConsecutiveFailures

func (s *Store) ConsecutiveFailures(ctx context.Context, tool string, limit int) (int, error)

ConsecutiveFailures counts recent non-success runs for the active namespace and tool. @intent power escalation decisions without leaking cross-namespace failure history.

func (*Store) GetState

func (s *Store) GetState(ctx context.Context, tool string) (*model.PostprocessPolicyState, error)

GetState returns the latest stored postprocess policy for the active namespace and tool. @intent expose the current automatic policy decision without scanning historical runs.

func (*Store) RecordRun

func (s *Store) RecordRun(ctx context.Context, record RunRecord) error

RecordRun appends one postprocess execution result and updates the latest policy snapshot. @intent preserve the audit trail needed for failure escalation while keeping a cheap current-state lookup. @sideEffect writes a run log row and upserts namespace-scoped policy state.

func (*Store) Reset

func (s *Store) Reset(ctx context.Context, tool string) error

Reset records a successful reset marker for the named postprocess tool. @intent clear automatic fail_closed escalation after an operator has remediated the underlying issue.

func (*Store) Status

func (s *Store) Status(ctx context.Context, opts StatusOptions) (*StatusSummary, error)

Status summarizes fail-closed state and recent failures for the requested scope. @intent give operators one status view that explains why automatic postprocess execution is degraded.

Jump to

Keyboard shortcuts

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