memory

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalTargets

func MarshalTargets(names []string) string

MarshalTargets serialises a slice of entity/relation names to a JSON string.

func OpenDB

func OpenDB(dbURL string) (*gorm.DB, error)

Types

type AuditEvent

type AuditEvent struct {
	ID        string    `gorm:"primaryKey"`
	CreatedAt time.Time `gorm:"autoCreateTime"`
	Agent     string
	Tool      string
	Operation string
	Targets   string // JSON array of entity/relation names
	Count     int
	Outcome   string // "ok" | "error"
	ErrorMsg  string
}

AuditEvent is the GORM model persisted to the audit_events table.

type AuditFilter

type AuditFilter struct {
	Agent     string
	Tool      string
	Operation string
	Outcome   string
	Since     time.Time
	Limit     int
}

AuditFilter constrains Query results.

type AuditStore

type AuditStore interface {
	Write(ctx context.Context, e AuditEvent) error
	Query(ctx context.Context, f AuditFilter) ([]AuditEvent, int64, error)
	Summary(ctx context.Context, window time.Duration) (AuditSummary, error)
}

AuditStore is the port used by GraphAuditLogger and the MCP tools.

type AuditSummary

type AuditSummary struct {
	TotalMutations int
	ByAgent        map[string]int
	ByOperation    map[string]int
	ErrorRate      float64
	RiskyEvents    []AuditEvent
}

AuditSummary is returned by AuditStore.Summary.

type ContentCache

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

func NewContentCache

func NewContentCache(db *gorm.DB, enabled bool, maxSize int) *ContentCache

func (*ContentCache) Count

func (cc *ContentCache) Count() (int64, error)

func (*ContentCache) DeleteOrphanedContent

func (cc *ContentCache) DeleteOrphanedContent(activeRepos []string) error

func (*ContentCache) ListDocs

func (cc *ContentCache) ListDocs(repoName string) ([]DocRecord, error)

func (*ContentCache) NeedsUpdate

func (cc *ContentCache) NeedsUpdate(repoName, path, sha string) bool

func (*ContentCache) Search

func (cc *ContentCache) Search(query, repoName, fileType string) ([]ContentMatch, error)

func (*ContentCache) SearchMode

func (cc *ContentCache) SearchMode() string

func (*ContentCache) Upsert

func (cc *ContentCache) Upsert(repoName, path, sha, content, fileType string) error

type ContentMatch

type ContentMatch struct {
	RepoName string `json:"repo_name"`

	Path string `json:"path"`

	FileType string `json:"file_type,omitempty"`

	Snippet string `json:"snippet"`
}

type DBAuditStore

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

DBAuditStore is the SQLite/Postgres implementation of AuditStore.

func NewAuditStore

func NewAuditStore(db *gorm.DB) (*DBAuditStore, error)

NewAuditStore creates the audit_events table (if absent) and returns a store.

func (*DBAuditStore) Query

Query retrieves audit events matching the filter. Returns the page and total count.

func (*DBAuditStore) Summary

func (s *DBAuditStore) Summary(_ context.Context, window time.Duration) (AuditSummary, error)

Summary returns anomaly-focused metrics over the given rolling window.

func (*DBAuditStore) Write

func (s *DBAuditStore) Write(_ context.Context, e AuditEvent) error

Write persists one audit event. A UUIDv7 primary key is generated here so ORDER BY id gives chronological order without an extra index.

type DocRecord

type DocRecord struct {
	RepoName string

	Path string

	DocID string // "<RepoName>#<Path>"

	Content string
}

type Entity

type Entity struct {
	Name string `json:"name"`

	EntityType string `json:"entityType"`

	Observations []string `json:"observations"`
}

type IntegrationEdge

type IntegrationEdge struct {
	Target     string `json:"target"`
	Schema     string `json:"schema,omitempty"`      // event-topic schema name
	Version    string `json:"version,omitempty"`     // api version
	Paths      int    `json:"paths,omitempty"`       // api path count
	Confidence string `json:"confidence"`            // "authoritative" | "inferred"
	SourceRepo string `json:"source_repo,omitempty"` // originating repo
}

IntegrationEdge is a single integration relationship entry in an IntegrationMap.

type IntegrationMap

type IntegrationMap struct {
	Service      string            `json:"service"`
	Publishes    []IntegrationEdge `json:"publishes"`
	Subscribes   []IntegrationEdge `json:"subscribes"`
	ExposesAPI   []IntegrationEdge `json:"exposes_api"`
	ProvidesGRPC []IntegrationEdge `json:"provides_grpc"`
	GRPCDeps     []IntegrationEdge `json:"grpc_deps"`
	Calls        []IntegrationEdge `json:"calls"`
	Coverage     string            `json:"graph_coverage"` // "full" | "partial" | "inferred" | "none"
}

IntegrationMap aggregates all integration relationships for a service.

type KnowledgeGraph

type KnowledgeGraph struct {
	Entities []Entity `json:"entities"`

	Relations []Relation `json:"relations"`
}

type MemoryService

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

func NewMemoryService

func NewMemoryService(db *gorm.DB) *MemoryService

func (*MemoryService) AddObservations

func (srv *MemoryService) AddObservations(obs []Observation) ([]Observation, error)

func (*MemoryService) CreateEntities

func (srv *MemoryService) CreateEntities(entities []Entity) ([]Entity, error)

func (*MemoryService) CreateRelations

func (srv *MemoryService) CreateRelations(relations []Relation) ([]Relation, error)

func (*MemoryService) DeleteEntities

func (srv *MemoryService) DeleteEntities(names []string) error

func (*MemoryService) DeleteObservations

func (srv *MemoryService) DeleteObservations(deletions []Observation) error

func (*MemoryService) DeleteRelations

func (srv *MemoryService) DeleteRelations(relations []Relation) error

func (*MemoryService) EntityCount

func (srv *MemoryService) EntityCount() (int64, error)

func (*MemoryService) EntityTypeCounts

func (srv *MemoryService) EntityTypeCounts() (map[string]int64, error)

func (*MemoryService) FindPath

func (srv *MemoryService) FindPath(from, to string, maxDepth int) ([]PathEdge, error)

func (*MemoryService) GetIntegrationMap

func (srv *MemoryService) GetIntegrationMap(ctx context.Context, service string, depth int) (IntegrationMap, error)

func (*MemoryService) ListEntities

func (srv *MemoryService) ListEntities(entityType string) (KnowledgeGraph, error)

func (*MemoryService) ListRelations

func (srv *MemoryService) ListRelations(relationType, fromEntity string) ([]Relation, error)

func (*MemoryService) OpenNodes

func (srv *MemoryService) OpenNodes(names []string) (KnowledgeGraph, error)

func (*MemoryService) OpenNodesFiltered

func (srv *MemoryService) OpenNodesFiltered(names []string, includeArchived bool) (KnowledgeGraph, error)

func (*MemoryService) ReadGraph

func (srv *MemoryService) ReadGraph() (KnowledgeGraph, error)

func (*MemoryService) SearchNodes

func (srv *MemoryService) SearchNodes(query string) (KnowledgeGraph, error)

func (*MemoryService) SearchNodesFiltered

func (srv *MemoryService) SearchNodesFiltered(query string, includeArchived bool) (KnowledgeGraph, error)

func (*MemoryService) TraverseGraph

func (srv *MemoryService) TraverseGraph(entity, relationType, direction string, maxDepth int) ([]TraverseNode, error)

func (*MemoryService) UpdateEntity

func (srv *MemoryService) UpdateEntity(oldName, newName, newType string) error

type Observation

type Observation struct {
	EntityName string `json:"entityName"`

	Contents []string `json:"contents"`

	Observations []string `json:"observations,omitempty"` // For deletion

}

type PathEdge

type PathEdge struct {
	From         string `json:"from"`
	RelationType string `json:"relationType"`
	To           string `json:"to"`
}

PathEdge is a single directed edge on the path between two entities. The edge reflects the actual stored direction regardless of traversal direction.

type Relation

type Relation struct {
	From string `json:"from"`

	To string `json:"to"`

	RelationType string `json:"relationType"`
}

type TraverseNode

type TraverseNode struct {
	Name         string   `json:"name"`
	EntityType   string   `json:"entityType"`
	Observations []string `json:"observations"`
	Distance     int      `json:"distance"`
	Path         []string `json:"path"` // entity names from start (exclusive) to this node (inclusive)
}

TraverseNode is a node reached during graph traversal, enriched with distance from the start entity and the path of entity names leading to it.

Jump to

Keyboard shortcuts

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