trace

package
v0.6.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidTraceID = errors.New("invalid trace ID")

ErrInvalidTraceID is returned when a trace ID contains characters that could escape the cortex directory (path traversal). Only IDs matching the YYYYMMDD-slug format produced by NewID are accepted.

Functions

func ContentHash added in v0.5.0

func ContentHash(body string) string

ContentHash returns the SHA-256 hash of a trace body, prefixed with "sha256:" for algorithm-explicitness. Used for integrity verification and federation sync optimization.

func IsValidID added in v0.5.1

func IsValidID(id string) bool

IsValidID reports whether id is a well-formed trace ID safe for use in filesystem paths. It rejects any ID containing path separators, dot segments, or characters outside the NewID slug alphabet.

func IsValidType

func IsValidType(t string) bool

func NewID

func NewID(title string) string

NewID generates a trace ID from a title: YYYYMMDD-slugified-title.

If the slugified title already begins with a date prefix (either `YYYYMMDD-` or `YYYY-MM-DD-`), the leading date is stripped before today's date is prepended. This is a defensive measure: agents commonly include dates in titles to mark when an event occurred (e.g., "20260402 dadbot heartbeat check"), and without the strip the resulting ID would carry two date prefixes (`20260402-20260402-dadbot-heartbeat-check`). The strip does not validate that the digits form a real calendar date — its only job is to prevent visual prefix duplication in the final ID.

Types

type Frontmatter

type Frontmatter struct {
	ID           string   `yaml:"id"`
	Title        string   `yaml:"title"`
	Type         string   `yaml:"type"`
	Author       string   `yaml:"author,omitempty"`
	Tags         []string `yaml:"tags,omitempty"`
	DerivedFrom  []string `yaml:"derived_from,omitempty"`
	Origin       string   `yaml:"origin,omitempty"`
	Created      string   `yaml:"created"`
	Updated      string   `yaml:"updated"`
	ContentHash  string   `yaml:"content_hash,omitempty"`
	SourceHash   string   `yaml:"source_hash,omitempty"`
	SourceLocked bool     `yaml:"source_locked,omitempty"`
}

type Trace

type Trace struct {
	Frontmatter
	Body string
}

func New

func New(title, traceType, author string, tags []string, body string) *Trace

func Parse

func Parse(data []byte) (*Trace, error)

func ParseFile

func ParseFile(path string) (*Trace, error)

func (*Trace) Write

func (t *Trace) Write(path string) error

type Type

type Type string
const (
	TypeFact        Type = "fact"
	TypeDecision    Type = "decision"
	TypePreference  Type = "preference"
	TypeContext     Type = "context"
	TypeSkill       Type = "skill"
	TypeIntent      Type = "intent"
	TypeObservation Type = "observation"
	TypeNote        Type = "note"
	TypeDivergence  Type = "divergence"
)

Jump to

Keyboard shortcuts

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