knowledge

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package knowledge is the project's memory (#451): lessons a task learned, kept as one markdown file each under .orch/knowledge/ so they are versioned and reviewed with the code, and handed to the tasks that come later.

A lesson is YAML front matter (id, title, area, tags, source, task, created) and a short body: what happened and what worked. The files are the truth; the FTS5 index in orch.db (state.RankKnowledge) is a cache rebuilt from them on every search.

Index

Constants

View Source
const (
	// EventEdited is an operator's add, edit or removal of a lesson; extra
	// names the action, the lesson and who did it.
	EventEdited = "knowledge_edited"
	// EventUsed is a dispatch whose prompt carried lessons; extra lists them.
	EventUsed = "knowledge_used"
)

The events the project knowledge is recorded as (#453).

View Source
const (
	MaxLines = 15
	MaxChars = 600
)

MaxLines and MaxChars are how much of one lesson's body a dispatch prompt carries; `orch knowledge curate` asks for lessons that fit.

View Source
const CurateTaskPrefix = "knowledge-curate-"

CurateTaskPrefix starts the id of every `orch knowledge curate` task (#452): a task in the database only, never in tasks.json.

View Source
const Dir = ".orch/knowledge"

Dir is where a project keeps its lessons, relative to its root.

View Source
const KindRule = "rule"

KindRule marks an operator's rule (#505): a constraint every task touching its area must follow, carried in the prompt outside knowledge.max_in_prompt and handed to the local verify's reviewer. A file without a kind is a lesson.

Variables

View Source
var ErrNoLesson = errors.New("no lesson")

ErrNoLesson is an id no lesson under Dir has.

View Source
var Sources = []string{"agent", "verify", "review", "conflict", "operator"}

Sources are who can write a lesson.

Functions

func AreaMatches

func AreaMatches(l Lesson, paths []string) bool

AreaMatches reports whether one of the lesson's areas covers one of paths: the same path, a directory above it, or a glob matching it (`**` matches any depth). A lesson with no area matches nothing here; it can still be found by its words.

func Marshal

func Marshal(l Lesson) []byte

Marshal is the file a lesson is written as.

func Query

func Query(text string) string

Query turns free text into an FTS5 query: its words, each quoted, any of them. Empty when the text has no word worth searching for.

func Remove

func Remove(root, id string) error

Remove deletes the lesson with id under root.

func Retries

func Retries(t state.TaskRuntime) int

Retries is a finished task's dispatches past the first plus its CI retries; 0 is a first-try success. `orch knowledge stats` and Usage count with it.

func Usage

func Usage(events []state.Event, done []state.TaskRuntime) map[string]Use

Usage reads the EventUsed events against the done tasks, by lesson id.

Types

type Editor

type Editor struct {
	Root string
	// Events, when set, gets one EventEdited per change.
	Events EventAppender
	// Source names who edited, in the event: cli, dashboard.
	Source string
}

Editor is the one way the operator changes the lessons, from `orch knowledge add|rm` and from the dashboard alike: the file is written by Add, Update or Remove, then the change is recorded as an event.

func (Editor) Add

func (e Editor) Add(ctx context.Context, l Lesson, now time.Time) (Lesson, error)

Add writes a new lesson.

func (Editor) Remove

func (e Editor) Remove(ctx context.Context, id string, now time.Time) error

Remove deletes lesson id.

func (Editor) Update

func (e Editor) Update(ctx context.Context, id string, l Lesson, now time.Time) (Lesson, error)

Update rewrites lesson id.

type EventAppender

type EventAppender interface {
	AppendEvent(ctx context.Context, runID string, e state.Event) error
}

EventAppender is the slice of state.Backend an Editor records with.

type Lesson

type Lesson struct {
	ID      string   `yaml:"id" json:"id"`
	Title   string   `yaml:"title" json:"title"`
	Kind    string   `yaml:"kind,omitempty" json:"kind,omitempty"`
	Area    []string `yaml:"area,omitempty" json:"area,omitempty"`
	Tags    []string `yaml:"tags,omitempty" json:"tags,omitempty"`
	Source  string   `yaml:"source" json:"source"`
	Task    string   `yaml:"task,omitempty" json:"task,omitempty"`
	Created string   `yaml:"created" json:"created"`
	Body    string   `yaml:"-" json:"body"`
	// Path is the file, relative to the root it was loaded from.
	Path string `yaml:"-" json:"path"`
}

Lesson is one file under Dir.

func Add

func Add(root string, l Lesson, now time.Time) (Lesson, error)

Add validates l, fills its id and created date, and writes it under root's Dir without overwriting another lesson. It returns l as written.

func ForTask

func ForTask(ctx context.Context, r Ranker, root string, task model.Task, specRoot string, n int) ([]Lesson, error)

ForTask loads root's lessons and selects the ones task's prompt carries: by its files and its spec file, then by its title and description.

func ForTaskWithRules

func ForTaskWithRules(ctx context.Context, r Ranker, root string, task model.Task, specRoot string, n int) (rules, lessons []Lesson, err error)

ForTaskWithRules is ForTask, and the rules whose area covers the task's files, all of them, outside n (#505).

func Load

func Load(root string) ([]Lesson, error)

Load reads every lesson under root's Dir, sorted by id. No directory is no lessons.

func Parse

func Parse(raw []byte) (Lesson, error)

Parse reads one lesson file: front matter between `---` lines, then the body.

func Rules

func Rules(lessons []Lesson, paths []string) []Lesson

Rules are the operator's rules among lessons whose area covers one of paths. A rule with no area covers nothing: it would reach every task.

func Search(ctx context.Context, r Ranker, lessons []Lesson, text string, n int) ([]Lesson, error)

Search ranks lessons for text by BM25, best first, at most n.

func Select

func Select(ctx context.Context, r Ranker, lessons []Lesson, paths []string, text string, n int) ([]Lesson, error)

Select picks the lessons a task's prompt carries: those whose area covers one of the task's paths come first, then those its text finds, each group in BM25 order, at most n. Rules are not lessons and are never picked here.

func Update

func Update(root, id string, l Lesson) (Lesson, error)

Update rewrites the lesson with id under root with l's title, body, area, tags, task and source; its id, file and created date stay.

type Ranker

type Ranker interface {
	RankKnowledge(ctx context.Context, docs []state.KnowledgeDoc, query string, limit int) ([]string, error)
}

Ranker is the search index: state.SQLite.

type Use

type Use struct {
	Prompts  int `json:"prompts"`
	Tasks    int `json:"tasks"`
	FirstTry int `json:"first_try"`
}

Use is what a lesson did: how many prompts carried it, how many of the tasks they were for are done, and how many of those were a first-try success.

Jump to

Keyboard shortcuts

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