Files
archie/internal/domain/audit/retention.go
T
sam 6a25153659 docs(vale): reject em dashes, and remove the ones on the tree (#2149)
AGENTS.md forbids em dashes in prose, comments and user-facing strings, and
nothing checked it: Google.EmDash only flags a dash with a space on both sides,
so a bare U+2014 passed.

Archie.EmDash rejects U+2014 for Markdown, templates and Go, with a message
naming the alternatives. The 40 occurrences it finds are rewritten as a comma,
a colon, brackets or a second sentence, and scratch trees are out of scope so a
run over the repository reports on what the repository holds.
2026-11-27 19:33:06 +11:00

107 lines
3.6 KiB
Go

package audit
import (
"slices"
"github.com/samcharles93/archie-core/internal/events"
)
// The audit retention policy: which runtime event kinds the sweep may delete,
// and which it must keep no matter what an instance setting says. The lists are
// code, not settings: a stored document chooses a window for a prunable kind
// but can never widen this boundary, and a security record is never deleted.
// observabilityEventKinds is the high-volume observability trail the sweep may
// delete. agent_transcript leads because it is the largest payload by far; the
// task-attempt view shows transcripts while they are kept and still works when
// they are gone.
func observabilityEventKinds() []string {
return []string{
events.KindAgentTranscript,
events.KindStageStart,
events.KindAgentFinish,
events.KindToolCall,
events.KindLog,
events.KindTurnCompleted,
events.KindConfigCaptured,
events.KindCuratorRun,
events.KindCuratorAction,
events.KindCuratorError,
events.KindJobRun,
events.KindJobError,
}
}
// protectedEventKinds are the kinds the sweep must never delete: security
// relevant records (approvals and rejections, retries, cancellation and
// abandonment, pull-request actions, delivery records, binding and mapping
// changes, alerts, update reports) and the two observability kinds a product
// read depends on. stage_finish is the only source for StageStats' slowest
// stages and most failures; changes_captured is what api_tasks_changes rebuilds
// a task's captured-changes view from. Neither has a fallback, so pruning them
// would silently change what the product shows. Keeping the list here, rather
// than in a comment, is what lets the prunable predicate refuse a kind that
// appears in both lists.
func protectedEventKinds() []string {
return []string{
events.KindStageFinish,
events.KindChangesCaptured,
events.KindTaskQueued,
events.KindDeliveryRecorded,
events.KindParked,
events.KindOutcome,
events.KindChatOutcome,
events.KindPRMerged,
events.KindPRRejected,
events.KindPRClosed,
events.KindPRMergeRequested,
events.KindTaskDead,
events.KindOperatorApproved,
events.KindOperatorRejected,
events.KindAgentApproved,
events.KindAgentRejected,
events.KindTaskApproved,
events.KindTaskRejected,
events.KindOperatorRereviewed,
events.KindAgentRereviewed,
events.KindTaskRereviewed,
events.KindTaskRetried,
events.KindTaskCancelled,
events.KindTaskStopped,
events.KindTaskAbandoned,
events.KindRemediationRound,
events.KindReviewApproved,
events.KindStepRetried,
events.KindTaskWithdrawn,
events.KindTaskArchiveRequested,
events.KindWorkRequestSubmitted,
events.KindAlert,
events.KindBindingChanged,
events.KindMappingChanged,
events.KindBindingStarted,
events.KindWorkflowCallStarted,
events.KindIdentityStarted,
events.KindWorkflowCallFinished,
events.KindUpdateReport,
// Written by the daemon's binding dispatch as a bare literal.
"binding_dispatch_failure",
}
}
// PrunableEventKinds returns the event kinds an instance's audit retention
// setting may give a window to, in display order. The protected set is
// subtracted, so a kind accidentally listed in both is kept rather than
// deleted.
func PrunableEventKinds() []string {
protected := protectedEventKinds()
return slices.DeleteFunc(slices.Clone(observabilityEventKinds()), func(kind string) bool {
return slices.Contains(protected, kind)
})
}
// PrunableEventKind reports whether kind is one the sweep may delete. Unknown
// kinds and security records are not prunable.
func PrunableEventKind(kind string) bool {
return slices.Contains(PrunableEventKinds(), kind)
}