services

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Bundles of markdown files in and out of Postgres, ported from 2de90d2:src/keepsake/cli/__init__.py.

The seven tool bodies, ported from 2de90d2:src/keepsake/server/tools.py. The tenant comes from the request's caller, so no tool takes one, and no tool returns a body the agent could not read.

Index

Constants

View Source
const (
	// DefaultBodyChars is the window the platform's triage agent cut bodies to before keepsake did.
	DefaultBodyChars = 40_000
	// MaxLinks is the link count the platform's triage agent capped each list to.
	MaxLinks = 25
	// FrontmatterBytes is the JSON size past which read drops trailing frontmatter keys.
	FrontmatterBytes = 4096
	// SnippetBytes leaves search's two 25-word passages whole and stops one unbroken run.
	SnippetBytes = 512
)

The bounds on what one read, search or grep returns, so a single call cannot fill an agent's context.

View Source
const ImportActor = "process:import"

ImportActor is the OKF §7 process actor an import records, since it copies a bundle in.

Variables

View Source
var ProvenanceKeys = []string{"sources", "generated"}

ProvenanceKeys are left out of read unless included, since every import and write grows them.

Functions

func Prune

func Prune(ctx context.Context, cs *repositories.ConceptRepository, r Retention, now time.Time) (reads, revisions int, err error)

Prune applies r to every tenant, one tenant at a time, and returns how many reads and revisions it deleted.

func ValidateBundle

func ValidateBundle(root string) (errs, warnings []string, err error)

ValidateBundle returns every rule the bundle breaks, and its broken links as warnings, since OKF §6.1 allows them.

Types

type BundleService

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

BundleService moves bundles of markdown files in and out of a tenant's concepts.

func (*BundleService) Export

func (b *BundleService) Export(ctx context.Context, tenant uuid.UUID, root string) (int, error)

Export writes the corpus out as a bundle, index and log included.

func (*BundleService) Import

func (b *BundleService) Import(ctx context.Context, tenant uuid.UUID, root string) (int, error)

Import stores the whole bundle in one transaction, all or nothing.

func (*BundleService) Replace

func (b *BundleService) Replace(ctx context.Context, tenant uuid.UUID, prefix string, concepts []okf.Concept, actor string) (written, deleted int, err error)

Replace makes the tenant's concepts under prefix exactly concepts.

type Card

type Card struct {
	SearchHit
	Snippet string `json:"snippet"`
	okf.Signals
}

Card is a search result: a SearchHit, the passages that match, and the OKF §5 signals.

type Concept

type Concept struct {
	Path                 string   `json:"path"`
	Type                 string   `json:"type"`
	Title                string   `json:"title"`
	Description          string   `json:"description"`
	Body                 string   `json:"body"`
	BodyChars            int      `json:"body_chars"`
	NextOffset           *int     `json:"next_offset"`
	Frontmatter          *okf.Map `json:"frontmatter"`
	FrontmatterTruncated bool     `json:"frontmatter_truncated"`
	Version              int      `json:"version"`
	Links                []string `json:"links"`
	LinksCount           int      `json:"links_count"`
	Backlinks            []string `json:"backlinks"`
	BacklinksCount       int      `json:"backlinks_count"`
	okf.Signals
}

type ConceptService

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

func NewConceptService

func NewConceptService(cs *repositories.ConceptRepository, tenant uuid.UUID, actor string) *ConceptService

func (*ConceptService) Actor

func (t *ConceptService) Actor() string

func (*ConceptService) As

func (t *ConceptService) As(tenant uuid.UUID, actor string) *ConceptService

As returns a copy acting for tenant as actor.

func (*ConceptService) Create

func (t *ConceptService) Create(ctx context.Context, path string, kw map[string]any) (WriteResult, error)

func (*ConceptService) Grep

func (t *ConceptService) Grep(ctx context.Context, pattern string, limit int) ([]GrepHit, error)

func (*ConceptService) List

func (t *ConceptService) List(ctx context.Context, prefix string, limit int) (Listing, error)

List returns the first limit paths under prefix, with counts and a total over all of them.

func (*ConceptService) PoolSize

func (t *ConceptService) PoolSize() int

PoolSize is the most database connections the service can hold at once.

func (*ConceptService) Read

func (t *ConceptService) Read(ctx context.Context, path string, o ReadOptions) (*Concept, error)

Read returns one page of the concept at path, or nil when nothing is stored there.

func (*ConceptService) Relate

func (t *ConceptService) Relate(ctx context.Context, fromPath, toPath string) (any, error)

Relate appends the edge, retrying past concurrent writers, since appending a link commutes.

func (*ConceptService) Search

func (t *ConceptService) Search(ctx context.Context, query string, limit int, prefix *string) ([]Card, error)

func (*ConceptService) Tenant

func (t *ConceptService) Tenant() uuid.UUID

func (*ConceptService) Update

func (t *ConceptService) Update(ctx context.Context, path string, expectedVersion *int, kw map[string]any) (any, error)

Update returns a WriteResult, or a ConflictResult when expectedVersion is stale.

type ConflictResult

type ConflictResult struct {
	Conflict       bool   `json:"conflict"`
	CurrentVersion int    `json:"current_version"`
	CurrentBody    string `json:"current_body"`
}

type ConsoleService

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

ConsoleService serves the admin console's reads.

func (*ConsoleService) Activity

func (s *ConsoleService) Activity(ctx context.Context, tenant *uuid.UUID, limit int) ([]models.Revision, error)

func (*ConsoleService) Detail

func (s *ConsoleService) Detail(ctx context.Context, tenant uuid.UUID, path string, limit int) (*okf.Concept, []string, []models.Revision, error)

func (*ConsoleService) Graph

func (s *ConsoleService) Graph(ctx context.Context, tenant uuid.UUID) (Graph, error)

func (*ConsoleService) Grep

func (s *ConsoleService) Grep(ctx context.Context, tenant uuid.UUID, pattern string, limit int) ([]GrepHit, error)

func (*ConsoleService) Page

func (s *ConsoleService) Page(ctx context.Context, tenant *uuid.UUID, prefix string, limit, offset int) ([]models.Summary, int, error)

func (*ConsoleService) Search

func (s *ConsoleService) Search(ctx context.Context, tenant uuid.UUID, query string, limit int) ([]SearchHit, error)

func (*ConsoleService) Tenants

func (s *ConsoleService) Tenants(ctx context.Context) ([]models.TenantCount, error)

func (*ConsoleService) Timeseries

func (s *ConsoleService) Timeseries(ctx context.Context, tenant *uuid.UUID, unit string, n int) ([]models.Bucket, error)

func (*ConsoleService) Totals

func (s *ConsoleService) Totals(ctx context.Context, tenant *uuid.UUID) (models.Totals, error)

type Graph

type Graph struct {
	Nodes     []GraphNode `json:"nodes"`
	Edges     [][2]string `json:"edges"`
	Truncated bool        `json:"truncated"`
}

type GraphNode

type GraphNode struct {
	Path  string `json:"path"`
	Type  string `json:"type"`
	Title string `json:"title"`
	// Missing marks a link target no concept holds: named by an agent, never written.
	Missing bool `json:"missing"`
}

type GrepHit

type GrepHit struct {
	Path    string `json:"path"`
	Snippet string `json:"snippet"`
}

type Listing

type Listing struct {
	Paths     []string `json:"paths"`
	Counts    *okf.Map `json:"counts"`
	Total     int      `json:"total"`
	Truncated bool     `json:"truncated"`
}

type ReadOptions

type ReadOptions struct {
	Offset   int
	MaxChars int
	// Include names the ProvenanceKeys to return.
	Include []string
}

ReadOptions bounds a Read. A zero MaxChars means DefaultBodyChars.

type Retention

type Retention struct {
	ReadDays     int
	RevisionDays int
	// RevisionKeep is how many of each path's newest revisions survive any age.
	RevisionKeep int
}

Retention is how long prune keeps reads and revisions. RevisionDays 0 keeps every revision.

type SearchHit

type SearchHit struct {
	Path        string  `json:"path"`
	Type        string  `json:"type"`
	Title       string  `json:"title"`
	Description string  `json:"description"`
	Score       float64 `json:"score"`
}

type ToolError

type ToolError struct{ Msg string }

ToolError is surfaced to the agent. It MUST NOT contain a concept body.

func (*ToolError) Error

func (e *ToolError) Error() string

type WriteResult

type WriteResult struct {
	Path    string `json:"path"`
	Version int    `json:"version"`
}

Jump to

Keyboard shortcuts

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