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
- Variables
- func AreaMatches(l Lesson, paths []string) bool
- func Marshal(l Lesson) []byte
- func Query(text string) string
- func Remove(root, id string) error
- func Retries(t state.TaskRuntime) int
- func Usage(events []state.Event, done []state.TaskRuntime) map[string]Use
- type Editor
- type EventAppender
- type Lesson
- func Add(root string, l Lesson, now time.Time) (Lesson, error)
- func ForTask(ctx context.Context, r Ranker, root string, task model.Task, specRoot string, ...) ([]Lesson, error)
- func ForTaskWithRules(ctx context.Context, r Ranker, root string, task model.Task, specRoot string, ...) (rules, lessons []Lesson, err error)
- func Load(root string) ([]Lesson, error)
- func Parse(raw []byte) (Lesson, error)
- func Rules(lessons []Lesson, paths []string) []Lesson
- func Search(ctx context.Context, r Ranker, lessons []Lesson, text string, n int) ([]Lesson, error)
- func Select(ctx context.Context, r Ranker, lessons []Lesson, paths []string, text string, ...) ([]Lesson, error)
- func Update(root, id string, l Lesson) (Lesson, error)
- type Ranker
- type Use
Constants ¶
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).
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.
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.
const Dir = ".orch/knowledge"
Dir is where a project keeps its lessons, relative to its root.
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 ¶
var ErrNoLesson = errors.New("no lesson")
ErrNoLesson is an id no lesson under Dir has.
var Sources = []string{"agent", "verify", "review", "conflict", "operator"}
Sources are who can write a lesson.
Functions ¶
func AreaMatches ¶
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 Query ¶
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 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.
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.
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 ¶
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 Rules ¶
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 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.