schema

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package schema holds LadyM's core data models.

All memory items — episodic events, consolidated facts, code symbols, and procedural playbooks — are represented by a single Memory record. This unification is what lets the recall pipeline treat "memory" and "codebase RAG" as one system (see ARCHITECTURE.md §1).

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidClaim = errors.New("invalid claim")
View Source
var ErrMemoryNotFound = errors.New("memory not found")

Functions

func ContentHash

func ContentHash(text string) string

ContentHash returns the blake2b-16 hex digest of text, mirroring ladym.layers.semantic.content_hash.

func EvidenceKind added in v0.9.0

func EvidenceKind(kind string) bool

func IsRetired added in v0.9.0

func IsRetired(m *Memory) bool

IsRetired preserves the supersedes metadata semantics used by existing data.

func IsSystemType added in v0.9.0

func IsSystemType(t MemoryType) bool

func IsUsable added in v0.9.0

func IsUsable(m *Memory) bool

IsUsable includes legacy knowledge without an explicit status.

func KnowledgeFingerprint added in v0.9.0

func KnowledgeFingerprint(m *Memory) string

func MaintenanceInputFingerprint added in v0.9.0

func MaintenanceInputFingerprint(m *Memory) (string, error)

Accounting stamps are not knowledge inputs to the operation that wrote them.

func ManagedRevision added in v0.9.0

func ManagedRevision(m *Memory) int64

func ManagedRevisionKey added in v0.9.0

func ManagedRevisionKey(m *Memory) string

func NewID

func NewID() string

NewID returns a fresh 32-hex-char id, mirroring Python's uuid4().hex.

func Now

func Now() float64

Now returns the current Unix time as a float64 (seconds since epoch), mirroring Python's time.time().

func ProjectedEdgeID added in v0.7.0

func ProjectedEdgeID(src, relation, dst string) string

ProjectedEdgeID returns the deterministic id for machine-projected edges so re-running a projection upserts instead of duplicating.

func SetClaimData added in v0.9.0

func SetClaimData(c *Claim)

func SourceFingerprint added in v0.9.0

func SourceFingerprint(m *Memory) (string, error)

SourceFingerprint captures trust, scope and TTL as well as literal content. Access statistics are deliberately excluded so reads cannot stale a topic.

func ValidateClaim added in v0.9.0

func ValidateClaim(content string, refs []EvidenceRef, scope ClaimScope, until float64) error

func ValidateEvidenceRef added in v0.9.0

func ValidateEvidenceRef(ref EvidenceRef, source *Memory) error

Types

type BootstrapRequest added in v0.9.0

type BootstrapRequest struct {
	TopicIDs    []string `json:"topic_ids"`
	Environment string   `json:"environment"`
	CodeVersion string   `json:"code_version"`
	Conditions  []string `json:"conditions"`
	TaskID      string   `json:"task_id"`
	Unit        string   `json:"unit"`
	Limit       int      `json:"limit"`
	Workspace   string   `json:"workspace"`
}

type BootstrapResponse added in v0.9.0

type BootstrapResponse struct {
	Content   string   `json:"content"`
	Unit      string   `json:"unit"`
	Model     string   `json:"model"`
	Used      int      `json:"used"`
	SourceIDs []string `json:"source_ids"`
}

type BuildTopicRequest added in v0.9.0

type BuildTopicRequest struct {
	Topic            string   `json:"topic"`
	InputIDs         []string `json:"input_ids"`
	ExpectedRevision int64    `json:"expected_revision"`
	Workspace        string   `json:"workspace"`
}

type Claim added in v0.9.0

type Claim struct {
	Memory          *Memory       `json:"memory,omitempty"`
	Revision        int64         `json:"revision"`
	Status          string        `json:"status"`
	Evidence        []EvidenceRef `json:"evidence_refs"`
	CounterEvidence []EvidenceRef `json:"counter_evidence"`
	Scope           ClaimScope    `json:"scope"`
	Verification    *Verification `json:"verification,omitempty"`
	ValidUntil      float64       `json:"valid_until"`
}

func ClaimFromMemory added in v0.9.0

func ClaimFromMemory(m *Memory) (*Claim, error)

type ClaimFeedback added in v0.9.0

type ClaimFeedback struct {
	ExpectedRevision int64         `json:"expected_revision"`
	Action           string        `json:"action"`
	Replacement      string        `json:"replacement"`
	Method           string        `json:"method"`
	Reason           string        `json:"reason"`
	Actor            string        `json:"actor"`
	Evidence         []EvidenceRef `json:"evidence_refs"`
}

type ClaimFeedbackRequest added in v0.9.0

type ClaimFeedbackRequest struct {
	ClaimFeedback
	Workspace string `json:"workspace"`
}

type ClaimScope added in v0.9.0

type ClaimScope struct {
	Environment string   `json:"environment"`
	CodeVersion string   `json:"code_version"`
	Conditions  []string `json:"conditions"`
}

type CodeRef

type CodeRef struct {
	SrcSymbol string `json:"src_symbol"`
	DstSymbol string `json:"dst_symbol"`
	RefKind   string `json:"ref_kind"`
}

CodeRef is a cross-reference between two symbols (calls/imports/defines).

type CodeSymbol

type CodeSymbol struct {
	MemoryID      string `json:"memory_id"`
	FilePath      string `json:"file_path"`
	SymbolKind    string `json:"symbol_kind"`
	QualifiedName string `json:"qualified_name"`
	Signature     string `json:"signature"`
	Docstring     string `json:"docstring"`
	LineStart     int    `json:"line_start"`
	LineEnd       int    `json:"line_end"`
	Language      string `json:"language"`
}

CodeSymbol is a structured projection of a code-bearing Memory.

type CreateClaimRequest added in v0.9.0

type CreateClaimRequest struct {
	Content    string        `json:"content"`
	Evidence   []EvidenceRef `json:"evidence_refs"`
	Scope      ClaimScope    `json:"scope"`
	Status     string        `json:"status"`
	ValidUntil float64       `json:"valid_until"`
	Workspace  string        `json:"workspace"`
}

type Edge

type Edge struct {
	ID        string         `json:"id"`
	SrcID     string         `json:"src_id"`
	Relation  string         `json:"relation"`
	DstID     string         `json:"dst_id"`
	Weight    float64        `json:"weight"`
	ValidFrom float64        `json:"valid_from"`
	ValidTo   *float64       `json:"valid_to"` // nil = still valid
	Metadata  map[string]any `json:"metadata"`
}

Edge is a Zettelkasten-style link between two memories (L4 associative).

func NewEdge

func NewEdge(srcID, relation, dstID string) *Edge

NewEdge returns an Edge with id/valid_from populated.

type EmbeddingIdentity added in v0.9.0

type EmbeddingIdentity struct {
	Provider  string `json:"provider"`
	Model     string `json:"model"`
	Tokenizer string `json:"tokenizer"`
	Dim       int    `json:"dim"`
}

EmbeddingIdentity names a vector space, including the tokenizer/version.

func (EmbeddingIdentity) Fingerprint added in v0.9.0

func (i EmbeddingIdentity) Fingerprint() string

func (EmbeddingIdentity) Validate added in v0.9.0

func (i EmbeddingIdentity) Validate() error

type EvidenceRef added in v0.9.0

type EvidenceRef struct {
	MemoryID    string `json:"memory_id"`
	Fingerprint string `json:"fingerprint"`
	Kind        string `json:"kind"`
	StartRune   int    `json:"start_rune"`
	EndRune     int    `json:"end_rune"`
}

type HybridRecallRequest added in v0.9.0

type HybridRecallRequest struct {
	Query     string `json:"query"`
	Limit     int    `json:"limit"`
	Workspace string `json:"workspace"`
}

type Layer

type Layer string

Layer is one of LadyM's seven memory layers (ARCHITECTURE.md §1).

const (
	LayerWorking      Layer = "L0_working"     // in-process scratch
	LayerEpisodic     Layer = "L1_episodic"    // time-stamped events
	LayerSemantic     Layer = "L2_semantic"    // consolidated facts + code analysis
	LayerProcedural   Layer = "L3_procedural"  // how-to playbooks
	LayerAssociative  Layer = "L4_associative" // graph edges (handled via Edge)
	LayerL5Mental     Layer = "L5_mental"      // mental models
	LayerL6Predictive Layer = "L6_predictive"  // forward intent
)

type MaintenanceJob added in v0.9.0

type MaintenanceJob struct {
	ID             string            `json:"id"`
	Workspace      string            `json:"workspace"`
	Operation      string            `json:"operation"`
	TargetID       string            `json:"target_id"`
	State          string            `json:"state"`
	Priority       int               `json:"priority,omitzero"`
	Owner          string            `json:"owner,omitempty"`
	ErrorCode      string            `json:"error_code,omitempty"`
	InputIDs       []string          `json:"input_ids"`
	Fingerprints   map[string]string `json:"fingerprints"`
	InputRevisions map[string]int64  `json:"input_revisions"`
	Args           map[string]any    `json:"args"`
	Revision       int64             `json:"revision"`
	Attempt        int               `json:"attempt"`
	NotBefore      float64           `json:"not_before"`
	LeaseUntil     float64           `json:"lease_until"`
	Checkpoint     map[string]any    `json:"checkpoint,omitempty"`
}

func MaintenanceJobFromMemory added in v0.9.0

func MaintenanceJobFromMemory(m *Memory) (*MaintenanceJob, error)

func (*MaintenanceJob) SetMemory added in v0.9.0

func (j *MaintenanceJob) SetMemory(m *Memory)

type MaintenanceReport added in v0.9.0

type MaintenanceReport struct {
	CandidateCount      int     `json:"candidate_count"`
	Calls               int     `json:"calls"`
	ReservedBytes       int     `json:"reserved_bytes"`
	MeasuredInputBytes  int     `json:"measured_input_bytes"`
	MeasuredOutputBytes int     `json:"measured_output_bytes"`
	CompletedJobs       int     `json:"completed_jobs"`
	PendingJobs         int     `json:"pending_jobs"`
	FailedJobs          int     `json:"failed_jobs"`
	ElapsedMS           float64 `json:"elapsed_ms"`
	StopReason          string  `json:"stop_reason"`
	Unit                string  `json:"unit"`
}

type Memory

type Memory struct {
	ID        string         `json:"id"`
	Layer     Layer          `json:"layer"`
	Type      MemoryType     `json:"type"`
	Content   string         `json:"content"`
	Summary   string         `json:"summary"`
	Tags      []string       `json:"tags"`
	Metadata  map[string]any `json:"metadata"`
	Source    string         `json:"source"`
	Workspace string         `json:"workspace"`

	CreatedAt    float64 `json:"created_at"`
	UpdatedAt    float64 `json:"updated_at"`
	LastAccessAt float64 `json:"last_access_at"`
	AccessCount  int     `json:"access_count"`
	Activation   float64 `json:"activation"`
	ContentHash  string  `json:"content_hash"`

	// Embedding is stored separately (BLOB) but kept on the model for
	// in-memory flows. Omitted from JSON when unset.
	Embedding []float32 `json:"embedding,omitempty"`
}

Memory is a single memory item; it maps to one row in the memories table.

func NewMemory

func NewMemory(layer Layer, typ MemoryType) *Memory

NewMemory returns a Memory with the id/timestamps pre-populated. Layer and Type are required; everything else defaults.

func (*Memory) Clone

func (m *Memory) Clone() *Memory

Clone returns a shallow copy with independent Tags and Metadata containers. Tags is always non-nil; Metadata preserves nil.

func (*Memory) Meta

func (m *Memory) Meta(key string) any

Meta returns the value for key in Metadata, or nil.

func (*Memory) MetaBool

func (m *Memory) MetaBool(key string) bool

MetaBool reports whether key is present with a truthy value in Metadata.

func (*Memory) MetaFloat

func (m *Memory) MetaFloat(key string) (float64, bool)

MetaFloat returns the float value for key (accepting JSON numbers) and ok.

func (*Memory) MetaString

func (m *Memory) MetaString(key string) string

MetaString returns the string value for key in Metadata, or "".

func (*Memory) Touch

func (m *Memory) Touch()

Touch marks the memory as accessed (called by the retriever).

type MemoryType

type MemoryType string

MemoryType is a sub-type within a layer. L2 is the most polymorphic.

const (
	TypeNote           MemoryType = "note"           // free-form working/semantic note
	TypeEvent          MemoryType = "event"          // episodic (agent, action, observation, outcome)
	TypeFact           MemoryType = "fact"           // consolidated semantic fact
	TypeCodeFile       MemoryType = "code_file"      // whole-file summary
	TypeCodeSymbol     MemoryType = "code_symbol"    // function/class/method/doc
	TypePlaybook       MemoryType = "playbook"       // procedural steps
	TypeSnippet        MemoryType = "snippet"        // verified reusable code
	TypeMentalModel    MemoryType = "mental_model"   // L5 mental model
	TypeForwardIntent  MemoryType = "forward_intent" // L6 forward intent
	TypeResource       MemoryType = "resource"       // L2 resource entity (operated-on target)
	TypeClaim          MemoryType = "claim"
	TypeEvidence       MemoryType = "evidence"
	TypeTopicView      MemoryType = "topic_view"
	TypeMaintenanceJob MemoryType = "maintenance_job"
	TypeTaskState      MemoryType = "task_state"
)

type MigrationStatus added in v0.9.0

type MigrationStatus struct {
	State             string            `json:"state"`
	ActiveFingerprint string            `json:"active_fingerprint"`
	TargetFingerprint string            `json:"target_fingerprint,omitempty"`
	Generation        string            `json:"generation,omitempty"`
	Cursor            string            `json:"cursor,omitempty"`
	Processed         int               `json:"processed"`
	RollbackAvailable bool              `json:"rollback_available"`
	AutoFinalize      bool              `json:"auto_finalize,omitempty"`
	ActiveIdentity    EmbeddingIdentity `json:"active_identity"`
	TargetIdentity    EmbeddingIdentity `json:"target_identity"`
}

type RecallResponse

type RecallResponse struct {
	Query               string          `json:"query"`
	Results             []*RecallResult `json:"results"`
	TierReached         int             `json:"tier_reached"`
	ReflectedSufficient bool            `json:"reflected_sufficient"`
	ElapsedMs           float64         `json:"elapsed_ms"`
}

RecallResponse is the full response from a recall call.

type RecallResult

type RecallResult struct {
	Memory *Memory  `json:"memory"`
	Score  float64  `json:"score"`
	Tier   int      `json:"tier"`
	Via    []string `json:"via"`
}

RecallResult is one hit returned by recall.

type RecordEvidenceRequest added in v0.9.0

type RecordEvidenceRequest struct {
	Kind      string `json:"kind"`
	Content   string `json:"content"`
	Outcome   string `json:"outcome"`
	Actor     string `json:"actor"`
	Workspace string `json:"workspace"`
}

type ScheduleMaintenanceRequest added in v0.9.0

type ScheduleMaintenanceRequest struct {
	Workspace string         `json:"workspace,omitempty"`
	Operation string         `json:"operation"`
	TargetID  string         `json:"target_id"`
	InputIDs  []string       `json:"input_ids"`
	Args      map[string]any `json:"args,omitempty"`
}

type SetTaskStateRequest added in v0.9.0

type SetTaskStateRequest struct {
	ID        string  `json:"id"`
	Goal      string  `json:"goal"`
	Next      string  `json:"next_step"`
	TTLS      float64 `json:"ttl_s"`
	Workspace string  `json:"workspace"`
}

type Stats

type Stats struct {
	TotalMemories      int            `json:"total_memories"`
	ByLayer            map[string]int `json:"by_layer"`
	ByType             map[string]int `json:"by_type"`
	Edges              int            `json:"edges"`
	CodeSymbols        int            `json:"code_symbols"`
	Workspaces         []string       `json:"workspaces"`
	DBPath             string         `json:"db_path"`
	AvgTokensPerMemory float64        `json:"avg_tokens_per_memory"`
}

Stats holds aggregate statistics for the stats tool/command.

type User added in v0.4.0

type User struct {
	Username     string  `json:"username"`
	PasswordHash string  `json:"password_hash"`
	Workspace    string  `json:"workspace"`
	Admin        bool    `json:"admin"`
	CreatedAt    float64 `json:"created_at"`
}

User is one row in the users table: a database-level account for the HTTP data-plane's Basic auth (see docs/superpowers/specs /2026-08-19-auth-console-client.md §2). PasswordHash holds a bcrypt hash; "" means the user is passwordless (only an empty password authenticates). Workspace is the forced workspace for non-admin users. The hash is produced and checked in the api/cli layers — the Store only persists the string.

type Verification added in v0.9.0

type Verification struct {
	Method    string        `json:"method"`
	Actor     string        `json:"actor"`
	CheckedAt float64       `json:"checked_at"`
	Evidence  []EvidenceRef `json:"evidence_refs"`
}

Jump to

Keyboard shortcuts

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