okf

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package okf implements Open Knowledge Format promotion and conformance checks.

Index

Constants

View Source
const DefaultTypeThreshold = 0.8

DefaultTypeThreshold is the P(argmax) a type suggestion needs before kb uses it or reports a disagreement (spec §12.3 default `okf_type`).

View Source
const NoneType = "none"

NoneType is the exit option of the type choice: no configured type fits.

View Source
const (
	OKFVersion = "0.1"
)

Variables

View Source
var ErrTypeRequired = errors.New("--type is required")

ErrTypeRequired is returned by Promote when no type can be chosen: no --type and either no vocabulary or no suggestion in the apply band.

Functions

func Check

func Check(ctx context.Context, bundlePath string, options CheckOptions) ([]models.LintIssue, error)

Check validates an OKF bundle and returns diagnostics.

func Columns

func Columns() []string

Columns returns the stable output column order for OKF diagnostics.

func HasErrors

func HasErrors(issues []models.LintIssue) bool

HasErrors reports whether any diagnostic should fail the command.

func InsertLogEntry

func InsertLogEntry(bundlePath string, when time.Time, title, conceptPath, sourcePath string) error

InsertLogEntry inserts a newest-first OKF log entry at the bundle root.

func RegenerateIndex

func RegenerateIndex(bundlePath string) error

RegenerateIndex rewrites the root OKF index from concept frontmatter.

func Rows

func Rows(issues []models.LintIssue) []map[string]any

Rows converts issues into formatter rows.

func SourceTopic

func SourceTopic(vaultPath, sourceDocPath string) (string, error)

SourceTopic returns the slug (vault-relative path) of the topic that holds the wiki document to promote: the type suggestion runs in that topic's decision session and its review queue.

Types

type AdvisoryOptions

type AdvisoryOptions struct {
	// Options is the type vocabulary with descriptions; empty skips
	// type_mismatch.
	Options []TypeOption
	// Threshold is the okf_type threshold (0 → DefaultTypeThreshold).
	Threshold float64
	// Decider computes missing answers; nil reads receipts only.
	Decider Decider
	// Topic is the bundle's topic reference for Decide (Root = bundle).
	// Concepts matching Topic.Exclude (decisions.exclude) get no advisory
	// finding: they are never judged.
	Topic decisions.TopicRef
	// Extras are the topic's extra okf_type banks, asked with type_mismatch
	// (answers only recorded in receipts).
	Extras []*questions.Bank
}

AdvisoryOptions configures the advisory findings of `kb okf check` (spec §11): type_mismatch and description_unsupported. They are always SeverityInfo, so they never fail the command, strict or not, until a calibration exists for them.

Answers are read from the bundle's receipts (`<bundle>/.decisions/ receipts.jsonl`), keyed by a subject that carries a hash of the question state, so an edited concept never reuses a stale answer. When Decider is set (`kb okf check --decide`), a concept without a stored answer is asked once and the receipt it writes serves every later check; without Decider the check never calls a model.

type CheckOptions

type CheckOptions struct {
	Types  []string
	Strict bool
	// Advisory enables the advisory findings type_mismatch and
	// description_unsupported (never errors); nil skips them.
	Advisory *AdvisoryOptions
}

CheckOptions configures OKF conformance checking.

type ConceptResult

type ConceptResult struct {
	WrittenPath     string   `json:"writtenPath"`
	Type            string   `json:"type"`
	LinksRewritten  int      `json:"linksRewritten"`
	UnresolvedLinks []string `json:"unresolvedLinks"`
	Warnings        []string `json:"warnings,omitempty"`
	// TypeSuggestion is the decision model's type suggestion, when asked.
	TypeSuggestion *TypeSuggestion `json:"typeSuggestion,omitempty"`
	// TypeWarning is set when --type disagrees with a confident suggestion.
	TypeWarning string `json:"typeWarning,omitempty"`
}

ConceptResult reports the concept written by Promote.

func Promote

func Promote(ctx context.Context, input PromoteInput) (ConceptResult, error)

Promote performs a mechanical, non-destructive wiki-to-OKF conversion.

type Decider

type Decider interface {
	Decide(ctx context.Context, r decisions.Request) (decisions.Result, error)
}

Decider asks the decision model; *decisions.Engine satisfies it.

type EngineTypeSuggester

type EngineTypeSuggester struct {
	Decider Decider
	Topic   decisions.TopicRef
	Options []TypeOption
	// Extras are the topic's extra okf_type question banks (spec §4.3):
	// their questions ride along in the same request and their answers are
	// only recorded in receipts.
	Extras []*questions.Bank
}

EngineTypeSuggester asks the okf_type choice over Options through a decision engine for one topic (receipts and cache live under Topic.Root).

func (EngineTypeSuggester) SuggestType

SuggestType asks one okf_type choice with state {document: {title, excerpt}}.

type PromoteInput

type PromoteInput struct {
	SourceDocPath string
	VaultPath     string
	TargetTopic   models.TopicInfo
	Type          string
	Description   string
	Types         []string
	Clock         func() time.Time
	// Suggester asks the decision model for the type (spec §11). Without
	// Type, its suggestion is used when P(argmax) ≥ TypeThreshold; with
	// Type, a disagreement at that probability becomes TypeWarning. nil
	// means no decision model: Type is then required.
	Suggester TypeSuggester
	// TypeThreshold is the okf_type threshold (0 → DefaultTypeThreshold).
	TypeThreshold float64
}

PromoteInput carries the data needed to promote one wiki document into an OKF bundle.

type TypeDocument

type TypeDocument struct {
	Subject string
	Title   string
	Body    string
}

TypeDocument is the document a type is suggested for. Subject names it in receipts and review items (topic-relative path).

type TypeOption

type TypeOption struct {
	Name        string
	Description string
}

TypeOption is one OKF type offered to the decision model: the type name is the option and Description its option text.

func TypeOptions

func TypeOptions(types []string, describe func(string) string) []TypeOption

TypeOptions builds the offered types from the vocabulary and a description lookup (nil or "" falls back to the type name).

type TypeScore

type TypeScore struct {
	Type        string  `json:"type"`
	Probability float64 `json:"probability"`
}

TypeScore is one ranked type of a suggestion.

type TypeSuggester

type TypeSuggester interface {
	SuggestType(ctx context.Context, doc TypeDocument) (TypeSuggestion, error)
}

TypeSuggester suggests the OKF type of a document.

type TypeSuggestion

type TypeSuggestion struct {
	Status      decisions.Status `json:"status"`
	Reason      string           `json:"reason,omitempty"`
	Type        string           `json:"type,omitempty"`
	Probability float64          `json:"probability"`
	Top         []TypeScore      `json:"top,omitempty"`
	ReceiptKey  string           `json:"receipt,omitempty"`
}

TypeSuggestion is the decision model's answer to "which configured type describes this document". Type is the argmax option (NoneType when no type fits); Status is not decided when the model gave no usable answer.

func (TypeSuggestion) Decided

func (s TypeSuggestion) Decided() bool

Decided reports whether the suggestion carries a usable answer.

func (TypeSuggestion) TopText

func (s TypeSuggestion) TopText() string

TopText renders the ranked types as "a 0.55, b 0.30, none 0.10".

Jump to

Keyboard shortcuts

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