history

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package history persists per-key validation records across runs so users can answer "what was the validity of this key over the last N runs?".

Records are keyed on (provider, sha256(key)) and include the run_id so a single key's history can be grouped and sorted by time.

On-disk format: ~/.kunji/history.jsonl — one JSON object per line.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByKey

func ByKey(records []Record) map[string][]Record

ByKey groups records by their (provider, key_sha256) composite key, sorted newest-first within each group.

func DefaultPath

func DefaultPath() string

DefaultPath returns ~/.kunji/history.jsonl (override with KUNJI_HISTORY_FILE).

func NewRunID

func NewRunID() string

Types

type Logger

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

Logger writes history records. A nil receiver is a no-op.

func Open

func Open(path, runID string) (*Logger, error)

Open prepares a history logger. runID should be unique per execution and is stamped on every record written by this logger.

func (*Logger) Close

func (l *Logger) Close() error

Close flushes and releases the underlying file. Idempotent.

func (*Logger) Emit

func (l *Logger) Emit(r *models.ValidationResult) error

Emit writes one history record for the given validation result.

func (*Logger) Path

func (l *Logger) Path() string

Path returns the on-disk path ("" for the no-op logger).

func (*Logger) RunID

func (l *Logger) RunID() string

RunID returns the run identifier stamped on records.

type Record

type Record struct {
	RunID      string `json:"run_id"`
	Timestamp  string `json:"ts"`
	Provider   string `json:"provider"`
	KeySHA256  string `json:"key_sha256"`
	IsValid    bool   `json:"is_valid"`
	StatusCode int    `json:"status_code,omitempty"`
	DurationMs int64  `json:"duration_ms,omitempty"`
}

Record is one history entry.

func ReadAll

func ReadAll(path string) ([]Record, error)

ReadAll loads the entire history file. Used by `kunji history`.

type Summary

type Summary struct {
	Provider    string
	KeySHA256   string
	Latest      Record
	History     []Record
	ValidStreak int
	TotalRuns   int
	ValidRuns   int
}

Summary describes the latest state of one key.

func Summarize

func Summarize(records []Record) []Summary

Summarize produces one Summary per distinct key, including its latest record and a simple validity streak.

Jump to

Keyboard shortcuts

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