okf

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

Package okf is the Open Knowledge Format, publishable without the rest of keepsake.

Index

Constants

View Source
const (
	Unverified       = "unverified"
	MachineConfirmed = "machine-confirmed"
	HumanReviewed    = "human-reviewed"
)

The §5.3 trust tiers, lowest first.

View Source
const (
	MaxPath  = 1024
	MaxBody  = 256 * 1024
	MaxTitle = 4096
)

Postgres limits in bytes, refused in advance so the agent gets a sentence instead of a driver error.

View Source
const AttestedComputation = "Attested Computation"

AttestedComputation is the OKF §10 type whose contract Families checks.

Variables

This section is empty.

Functions

func ExtractLinks(body, p string) []string

ExtractLinks returns the concept paths body links to, deduplicated in first-seen order. It matches Python's (?<!!)\[[^\]]*\]\(\s*([^)\s]*)(?:\s+[^)]*)?\s*\) in linear time.

func Families added in v0.7.0

func Families(c Concept) map[string][]string

Families returns the OKF v0.2 §5 and §10 rules c breaks, keyed by the top-level frontmatter key at fault.

func IsActor added in v0.7.0

func IsActor(s string) bool

IsActor reports whether s is an OKF §7 actor: <producer>/<version>, human:<id> or process:<id>.

func IsDecimal

func IsDecimal(s string) bool

IsDecimal is Python's str.isdecimal() over ASCII: non-empty and every byte a digit.

func PyDumps added in v0.7.0

func PyDumps(v any) (string, error)

PyDumps renders v as Python's default json.dumps: ", " and ": " separators, non-ASCII escaped.

func PyReprString

func PyReprString(s string) string

PyReprString is Python's repr(str): single quotes unless only double quotes avoid escaping.

func Reserved added in v0.4.0

func Reserved(path string) bool

Reserved reports whether path names index.md or log.md, which OKF reserves in every directory. A backslash counts as a separator, since a Windows export writes `a\index` as a/index.md.

func Resolve

func Resolve(target, directory string) (string, bool)

Resolve returns the concept path a link target names, relative to directory.

func Serialize

func Serialize(c Concept) (string, error)

Serialize renders a concept as an OKF document, failing only on a non-finite float.

func Storable added in v0.4.0

func Storable(c Concept) error

Storable returns why a parsed concept cannot be stored, or nil.

func Validate

func Validate(c Concept) []string

Validate returns every rule c breaks. An empty result means valid.

func ValidateIndex added in v0.8.0

func ValidateIndex(text string, root bool) []string

ValidateIndex returns the OKF §8 rules an index.md breaks. Only the bundle root's MAY hold frontmatter, and only okf_version.

func ValidateLog added in v0.8.0

func ValidateLog(text string) []string

ValidateLog returns the OKF §9 rules a log.md breaks: each date heading is YYYY-MM-DD, newest first.

Types

type Concept

type Concept struct {
	Path        string
	Type        string
	Title       string
	Description string
	Body        string
	Frontmatter *Map
	Links       []string
	Version     int
}

Concept is a single knowledge unit: a path, its frontmatter and its markdown body.

func Parse

func Parse(text, path string) (Concept, error)

Parse reads an OKF document. Frontmatter keeps only the fields Concept does not promote.

type Map

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

Map is an insertion-ordered JSON object of string, bool, nil, json.Number, int, NonFinite, []any or *Map.

func NewMap

func NewMap() *Map

func (*Map) Clone added in v0.5.0

func (m *Map) Clone() *Map

Clone copies the top level only; nested values are shared.

func (*Map) Delete

func (m *Map) Delete(k string)

func (*Map) Get

func (m *Map) Get(k string) (any, bool)

func (*Map) Keys

func (m *Map) Keys() []string

func (*Map) Len

func (m *Map) Len() int

func (*Map) MarshalJSON

func (m *Map) MarshalJSON() ([]byte, error)

func (*Map) Set

func (m *Map) Set(k string, v any)

Set adds or replaces a value. An existing key keeps its position.

func (*Map) UnmarshalJSON

func (m *Map) UnmarshalJSON(data []byte) error

UnmarshalJSON walks tokens so that key order survives; a map[string]any would lose it.

type NonFinite

type NonFinite string

NonFinite is a YAML .inf, -.inf or .nan. JSON cannot hold it, so it refuses to marshal.

const (
	PyInf    NonFinite = "inf"
	PyNegInf NonFinite = "-inf"
	PyNaN    NonFinite = "nan"
)

func (NonFinite) MarshalJSON

func (n NonFinite) MarshalJSON() ([]byte, error)

type Signals added in v0.5.0

type Signals struct {
	Status      string `json:"status"`
	Stale       bool   `json:"stale"`
	Trust       string `json:"trust"`
	GeneratedAt string `json:"generated_at"`
}

Signals are the trust and lifecycle facts a consumer derives from OKF v0.2 §5 frontmatter.

func Derive added in v0.5.0

func Derive(fm *Map, now time.Time) Signals

Derive reads Signals from fm as of now. A missing or malformed field reads as absent, never as an error.

type YAMLError

type YAMLError struct{ Msg string }

YAMLError is frontmatter that cannot be read. Callers prefix it with the file name.

func (YAMLError) Error

func (e YAMLError) Error() string

Directories

Path Synopsis
internal
yaml
Package yaml implements YAML support for the Go language.
Package yaml implements YAML support for the Go language.

Jump to

Keyboard shortcuts

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