incidents

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package incidents defines Incidentius's store-independent incident model and deterministic event projection. Persistence and transport adapters live in their owning repositories and depend on these validated types.

Index

Constants

View Source
const (
	ActorViaWeb   = "web"
	ActorViaCLI   = "cli"
	ActorViaAPI   = "api"
	ActorViaSlack = "slack"
)
View Source
const (
	ConfidenceSpeculative = "speculative"
	ConfidenceLikely      = "likely"
	ConfidenceConfirmed   = "confirmed"
)

Variables

View Source
var (
	ErrMutationConflict = errors.New("incident mutation id was reused with different content")
	ErrSequenceConflict = errors.New("incident event sequence changed")
)

Functions

func ValidateMutationID

func ValidateMutationID(value string) error

ValidateMutationID applies the store-wide receipt key rules to every transport and storage mutation before the identifier is used as a path.

Types

type Actor

type Actor struct {
	Kind ActorKind `json:"kind"`
	ID   string    `json:"id"`
	Via  string    `json:"via,omitempty"`
}

type ActorKind

type ActorKind string
const (
	ActorHuman  ActorKind = "human"
	ActorAgent  ActorKind = "agent"
	ActorSystem ActorKind = "system"
)

type AppendResult

type AppendResult struct {
	Event      Event    `json:"event"`
	Projection Incident `json:"projection"`
	Replayed   bool     `json:"replayed"`
}

type ArtifactRef

type ArtifactRef struct {
	Kind       RefKind             `json:"kind"`
	ID         string              `json:"id,omitempty"`
	Incident   *IncidentRef        `json:"incident,omitempty"`
	Project    *ProjectRef         `json:"project,omitempty"`
	Execution  *ExecutionRef       `json:"execution,omitempty"`
	Artifact   *ProjectArtifactRef `json:"artifact,omitempty"`
	Comparison *ComparisonRef      `json:"comparison,omitempty"`
}

ArtifactRef uses structured identities for cross-store artifacts. ID is reserved for incident-local hypotheses and events.

func (ArtifactRef) Validate

func (r ArtifactRef) Validate() error

type Assertion

type Assertion struct {
	Kind       AssertionKind `json:"kind"`
	Confidence string        `json:"confidence,omitempty"`
}

type AssertionKind

type AssertionKind string
const (
	AssertionObservation         AssertionKind = "observation"
	AssertionClaim               AssertionKind = "claim"
	AssertionQuestion            AssertionKind = "question"
	AssertionHypothesis          AssertionKind = "hypothesis"
	AssertionInference           AssertionKind = "inference"
	AssertionDeterministicResult AssertionKind = "deterministic-result"
)

type ComparisonRef

type ComparisonRef struct {
	Left  ExecutionRef `json:"left"`
	Right ExecutionRef `json:"right"`
}

func (ComparisonRef) Validate

func (r ComparisonRef) Validate() error

type CreatedPayload

type CreatedPayload struct {
	UID         string       `json:"uid"`
	Title       string       `json:"title"`
	Description string       `json:"description"`
	Projects    []ProjectRef `json:"projects,omitempty"`
}

type Event

type Event struct {
	ID        string      `json:"id"`
	Seq       uint64      `json:"seq"`
	At        time.Time   `json:"at"`
	VisibleAt time.Time   `json:"visibleAt"`
	Incident  IncidentRef `json:"incident"`
	// ImportedFrom preserves the original identity of an event copied by a
	// merge. Imported events remain timeline evidence but do not mutate the
	// survivor's active projection.
	ImportedFrom *ImportedEventRef `json:"importedFrom,omitempty"`
	Actor        Actor             `json:"actor"`
	Type         EventType         `json:"type"`
	Assertion    Assertion         `json:"assertion"`
	Refs         []ArtifactRef     `json:"refs,omitempty"`
	Payload      json.RawMessage   `json:"payload"`
}

func (Event) Validate

func (e Event) Validate() error

type EventDraft

type EventDraft struct {
	At        time.Time       `json:"at"`
	Actor     Actor           `json:"actor"`
	Type      EventType       `json:"type"`
	Assertion Assertion       `json:"assertion"`
	Refs      []ArtifactRef   `json:"refs,omitempty"`
	Payload   json.RawMessage `json:"payload"`
}

func (EventDraft) Validate

func (d EventDraft) Validate(incident IncidentRef) error

type EventType

type EventType string
const (
	EventIncidentCreated EventType = "incident.created"
	EventIncidentStatus  EventType = "incident.status"
	EventIncidentOutcome EventType = "incident.outcome"
	EventIncidentMerged  EventType = "incident.merged"
	EventNoteAdded       EventType = "note.added"
)

type ExecutionRef

type ExecutionRef struct {
	StoreID     string `json:"storeId"`
	ProjectID   string `json:"projectId"`
	ExecutionID string `json:"executionId"`
}

func (ExecutionRef) Validate

func (r ExecutionRef) Validate() error

type ImportedEventRef

type ImportedEventRef struct {
	Incident IncidentRef `json:"incident"`
	EventID  string      `json:"eventId"`
	Seq      uint64      `json:"seq"`
	MergeID  string      `json:"mergeId"`
}

func (ImportedEventRef) Validate

func (r ImportedEventRef) Validate(destination IncidentRef) error

type Incident

type Incident struct {
	Ref         IncidentRef  `json:"ref"`
	UID         string       `json:"uid"`
	Title       string       `json:"title"`
	Description string       `json:"description,omitempty"`
	Status      Status       `json:"status"`
	Outcome     Outcome      `json:"outcome,omitempty"`
	MergedInto  *IncidentRef `json:"mergedInto,omitempty"`
	Projects    []ProjectRef `json:"projects,omitempty"`
	Notes       []string     `json:"notes,omitempty"`
	LastSeq     uint64       `json:"lastSeq"`
}

Incident is the deterministic current or historical projection.

func Fold

func Fold(events []Event, at *time.Time) (Incident, error)

type IncidentRef

type IncidentRef struct {
	StoreID    string `json:"storeId"`
	IncidentID string `json:"incidentId"`
}

IncidentRef is the globally unambiguous identity of an incident.

func ParseIncidentRef

func ParseIncidentRef(value string) (IncidentRef, error)

func (IncidentRef) String

func (r IncidentRef) String() string

func (IncidentRef) Validate

func (r IncidentRef) Validate() error

type MergeMutation

type MergeMutation struct {
	MutationID string      `json:"mutationId"`
	Source     IncidentRef `json:"source"`
	Into       IncidentRef `json:"into"`
}

func (MergeMutation) Validate

func (m MergeMutation) Validate() error

type MergeResult

type MergeResult struct {
	Source   Incident `json:"source"`
	Into     Incident `json:"into"`
	Replayed bool     `json:"replayed"`
}

type MergedPayload

type MergedPayload struct {
	Into    IncidentRef `json:"into"`
	MergeID string      `json:"mergeId"`
}

type Mutation

type Mutation struct {
	MutationID  string      `json:"mutationId"`
	Incident    IncidentRef `json:"incident"`
	ExpectedSeq *uint64     `json:"expectedSeq,omitempty"`
	Event       EventDraft  `json:"event"`
}

func (Mutation) Validate

func (m Mutation) Validate() error

type NoteAddedPayload

type NoteAddedPayload struct {
	Body string `json:"body"`
}

type Outcome

type Outcome string
const (
	OutcomeResolved   Outcome = "resolved"
	OutcomeFalseAlarm Outcome = "false-alarm"
	OutcomeAccepted   Outcome = "accepted"
	OutcomeHandedOff  Outcome = "handed-off"
	OutcomeUnresolved Outcome = "unresolved"
)

type OutcomePayload

type OutcomePayload struct {
	Outcome Outcome `json:"outcome"`
}

type ProjectArtifactRef

type ProjectArtifactRef struct {
	StoreID     string `json:"storeId"`
	ProjectID   string `json:"projectId"`
	Environment string `json:"environment,omitempty"`
	ID          string `json:"id"`
}

func (ProjectArtifactRef) Validate

func (r ProjectArtifactRef) Validate() error

type ProjectRef

type ProjectRef struct {
	StoreID     string `json:"storeId"`
	ProjectID   string `json:"projectId"`
	Environment string `json:"environment,omitempty"`
}

func (ProjectRef) Validate

func (r ProjectRef) Validate() error

type RefKind

type RefKind string
const (
	RefExecution  RefKind = "execution"
	RefSnapshot   RefKind = "snapshot"
	RefAnnotation RefKind = "annotation"
	RefCheck      RefKind = "check"
	RefCompare    RefKind = "compare"
	RefQuery      RefKind = "query"
	RefBoard      RefKind = "board"
	RefFact       RefKind = "fact"
	RefHypothesis RefKind = "hypothesis"
	RefEvent      RefKind = "event"
	RefIncident   RefKind = "incident"
	RefProject    RefKind = "project"
)

type SharedLayout

type SharedLayout struct {
	IncidentDir         string
	Events              string
	Projection          string
	MutationReceiptsDir string
	StoreLock           string
	MergeIntentsDir     string
}

func LayoutFor

func LayoutFor(ref IncidentRef) (SharedLayout, error)

type Status

type Status string
const (
	StatusOpen          Status = "open"
	StatusInvestigating Status = "investigating"
	StatusMitigating    Status = "mitigating"
	StatusRecovering    Status = "recovering"
	StatusResolved      Status = "resolved"
	StatusWatching      Status = "watching"
	StatusClosed        Status = "closed"
)

type StatusPayload

type StatusPayload struct {
	Status Status `json:"status"`
}

type Store

type Store interface {
	Append(ctx context.Context, mutation Mutation) (AppendResult, error)
	Events(ctx context.Context, ref IncidentRef, afterSeq uint64) ([]Event, error)
	Projection(ctx context.Context, ref IncidentRef, at *time.Time) (Incident, error)
	Merge(ctx context.Context, mutation MergeMutation) (MergeResult, error)
}

Store is implemented once per configured StoreLocation. Append and Merge own cross-process exclusion, durable mutation receipts, and crash recovery.

type StoreLocation

type StoreLocation struct {
	StoreID string            `json:"storeId"`
	Kind    StoreLocationKind `json:"kind"`
	Project *ProjectRef       `json:"project,omitempty"`
}

StoreLocation selects where one incident store is hosted. All kinds use SharedLayout; adapters differ only in how their DALgo database is opened.

func (StoreLocation) Validate

func (l StoreLocation) Validate() error

type StoreLocationKind

type StoreLocationKind string
const (
	StoreLocationProjectRepository     StoreLocationKind = "project-repository"
	StoreLocationDedicatedRepository   StoreLocationKind = "dedicated-repository"
	StoreLocationApplicationRepository StoreLocationKind = "application-repository"
)

Jump to

Keyboard shortcuts

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