migrate

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package migrate contains utilities that convert existing markdown-backed memory content into the PostgreSQL wiki/graph schema (memory_nodes + memory_edges). The conversion logic is backend-agnostic: it produces plain NodeSpec/EdgeSpec values so it can be exercised by unit tests without a live database, and persisted by any concrete store implementation.

Index

Constants

This section is empty.

Variables

DerivedEdgeRels is the canonical set of edges rebuilt from node state.

ImplicitEdgeRels is the canonical set of edges derived automatically from node attributes (as opposed to explicit refs/supersedes/... authored later).

Functions

func NodeSlug

func NodeSlug(id, subject, topic string) string

NodeSlug returns the human/LLM-friendly slug used in wiki cross-references.

func ParseMemoryLinks(body string) []string

ParseMemoryLinks extracts referenced slugs from a memory body. It supports [[slug]] and markdown links. HTTP(S) links are ignored.

func Plan

func Plan(botID string, items []storefs.MemoryItem) ([]NodeSpec, []EdgeSpec)

Plan converts a bot's markdown memory items into wiki node specs plus the derived edges from shared profile_ref/topic/captured day and explicit wiki cross-references in node bodies. It performs no I/O and is safe to call in dry-run mode.

Layer classification is intentionally conservative: items without any hint fall back to LayerNote. This keeps the backfill deterministic and reversible until the typed-facts formation (P1) starts emitting explicit layers.

func Slugify

func Slugify(s string) string

Slugify normalizes a user/LLM-facing memory label for [[slug]] links.

Types

type EdgeRel

type EdgeRel string

EdgeRel is the canonical relationship type between two memory nodes.

const (
	EdgeSameProfile EdgeRel = "same_profile"
	EdgeSameTopic   EdgeRel = "same_topic"
	EdgeSameDay     EdgeRel = "same_day"
	EdgeRefs        EdgeRel = "refs"
)

type EdgeSpec

type EdgeSpec struct {
	BotID    string
	SrcNode  string
	DstNode  string
	Rel      EdgeRel
	Weight   float32
	Metadata map[string]any
}

EdgeSpec is a backend-agnostic description of a memory_edges row.

func PlanFromNodes

func PlanFromNodes(nodes []NodeSpec) []EdgeSpec

PlanFromNodes derives graph edges from an existing set of nodes (e.g. already persisted in the wiki store) without re-classifying them. It is the edge-derivation half of Plan, used by RebuildDerivedEdges.

type MemoryLayer

type MemoryLayer string

MemoryLayer is the canonical layer a memory node belongs to. Existing flat markdown entries that carry no layer hint are classified as LayerNote.

const (
	LayerPreference MemoryLayer = "preference"
	LayerIdentity   MemoryLayer = "identity"
	LayerContext    MemoryLayer = "context"
	LayerExperience MemoryLayer = "experience"
	LayerActivity   MemoryLayer = "activity"
	LayerPersona    MemoryLayer = "persona"
	LayerNote       MemoryLayer = "note"
)

type NodeSpec

type NodeSpec struct {
	ID               string
	BotID            string
	Body             string
	Hash             string
	Layer            MemoryLayer
	FactType         string
	Subject          string
	Confidence       float32
	Metadata         map[string]any
	SourceMessageIDs []string
	ProfileRef       string
	Topic            string
	CapturedAt       time.Time
	ExpiresAt        time.Time // zero value means "no expiry".
}

NodeSpec is a backend-agnostic description of a memory_nodes row, produced from a storefs.MemoryItem. Concrete store (PostgreSQL) translates this into their sqlc UpsertMemoryNodeParams.

type Result

type Result struct {
	BotID      string
	NodeCount  int
	EdgeCount  int
	LayerBreak map[MemoryLayer]int
}

Result summarises a wiki backfill pass for one bot.

func Summarise

func Summarise(botID string, nodes []NodeSpec, edges []EdgeSpec) Result

Summarise returns a Result for a planned node/edge set, suitable for CLI dry-run reporting.

Jump to

Keyboard shortcuts

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