improve

package
v0.0.1-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package improve implements the self-improvement loop (M9): /dream extracts durable facts from session traces and prunes stale memory, and /distill mines repeated tool sequences into skill, subagent, and command scaffolds.

Both halves are deliberately conservative. Dream summarizes with no tools attached, so it can never act on the trace it is reading. Distill only writes scaffolds — it never overwrites an existing file, so a generated artifact can always be edited by hand without a later run clobbering it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScaffoldCommand

func ScaffoldCommand(root, name string, p Pattern) (string, error)

ScaffoldCommand writes a command scaffold under <root>/.opencode/command/.

func ScaffoldSkill

func ScaffoldSkill(root, name string, p Pattern) (string, error)

ScaffoldSkill writes a SKILL.md scaffold under <root>/.claude/skills/<name>/, shaped so the SkillIndex (T-050) discovers it and BM25 (T-051) can rank it. It refuses to overwrite an existing scaffold.

func ScaffoldSubagent

func ScaffoldSubagent(root, name string, p Pattern) (string, error)

ScaffoldSubagent writes a subagent scaffold under <root>/.opencode/agent/, declaring the tools the mined sequence actually needs.

Types

type Dreamer

type Dreamer struct {
	// Provider is the model backend used for extraction.
	Provider ports.Provider
	// Model is the extraction model id ("<provider>/<model>").
	Model string
}

Dreamer extracts durable facts from a session trace with a summarizing model.

func (Dreamer) Extract

func (d Dreamer) Extract(ctx context.Context, trace []ports.Message) ([]string, error)

Extract reads a trace and returns the durable facts worth persisting. An empty trace yields nothing without consulting the model.

type Entry

type Entry struct {
	Text      string
	UpdatedAt time.Time
	// Pinned entries are never pruned, however old they get.
	Pinned bool
}

Entry is one stored memory line with the metadata pruning needs.

func Prune

func Prune(entries []Entry, now time.Time, policy PrunePolicy) (kept, pruned []Entry)

Prune splits entries into those to keep and those to drop. Entries are dropped when they exceed MaxAge, or when a newer entry says the same thing (case-insensitive). Pinned entries always survive. Input order is preserved among the kept entries.

type Kind

type Kind int

Kind is the artifact a pattern is best distilled into.

const (
	// KindSkill suits a multi-step, mutating workflow worth documenting.
	KindSkill Kind = iota
	// KindSubagent suits a read-only investigation that can run in isolation.
	KindSubagent
	// KindCommand suits a short, very frequent invocation.
	KindCommand
)

func SuggestKind

func SuggestKind(p Pattern) Kind

SuggestKind recommends what to distill a pattern into: a short but very frequent sequence is a command, a read-only sequence is a subagent, and anything that mutates the workspace is a skill.

func (Kind) String

func (k Kind) String() string

type MineOptions

type MineOptions struct {
	// MinLength is the shortest sequence considered a pattern (default 2).
	MinLength int
	// MinRuns is how many distinct runs must contain it (default 2).
	MinRuns int
	// MaxLength caps the sequence length considered (default 8).
	MaxLength int
}

MineOptions bounds the search. Zero values fall back to sane defaults rather than mining degenerate single-tool "patterns".

type Pattern

type Pattern struct {
	Tools []string
	// Runs is the number of distinct runs the sequence appeared in.
	Runs int
}

Pattern is a tool sequence that recurred across runs.

func MinePatterns

func MinePatterns(rs []Run, opts MineOptions) []Pattern

MinePatterns finds contiguous tool sequences that appear in at least MinRuns distinct runs. Frequency counts *runs*, not occurrences: a sequence repeated twice inside one session is one habit, not two. Results are ordered longest-first, then by how many runs contain them.

type PrunePolicy

type PrunePolicy struct {
	MaxAge time.Duration
}

PrunePolicy configures pruning. A zero MaxAge disables age-based pruning (deduplication still applies), so a misconfigured policy cannot silently wipe a project's memory.

type Run

type Run struct {
	Tools []string
}

Run is one recorded session's tool-call sequence.

Jump to

Keyboard shortcuts

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