extract

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package extract turns a coding-agent session transcript into candidate write-back notes. It is the input side of the flywheel: today write-back is opt-in (the Stop hook nudges once and ~most sessions still write nothing), so this lets Mesh pull the durable, reusable learnings out of a finished session automatically, for one-click review. BYOAI via the existing llm.Client (default `claude -p`, no API key). The model is the extractor; this package is the parse + prompt + validation around it.

Index

Constants

View Source
const DuplicateThreshold = 0.5

DuplicateThreshold is the title-similarity at or above which a candidate is treated as already-known (tuned so near-restatements match but distinct notes do not).

Variables

This section is empty.

Functions

func Judge

func Judge(ctx context.Context, client llm.Client, c Candidate) (keep bool, reason string, err error)

Judge rates whether a candidate is worth keeping, for measuring extraction precision in the benchmark. Strict by design (it is the precision gate, not a rubber stamp).

func TitleSimilarity

func TitleSimilarity(a, b string) float64

TitleSimilarity is the overlap coefficient of two titles' substantive tokens (0..1): intersection over the SMALLER token set. Overlap (not Jaccard) is the right measure for "does this candidate restate an existing note", because an existing note's title is often longer/compound (extra clauses) which would unfairly sink a Jaccard score.

Types

type Candidate

type Candidate struct {
	Type       string `json:"type"`       // decision | gotcha | post-mortem
	Title      string `json:"title"`      // specific, < ~12 words
	Do         string `json:"do"`         // one line, imperative
	Dont       string `json:"dont"`       // one line, the failure to avoid
	Why        string `json:"why"`        // one line, the reason/evidence
	Confidence string `json:"confidence"` // low | med | high (the model's self-rating)
}

Candidate is one extracted, not-yet-reviewed write-back note. Mirrors the fields mesh_append_note takes, so a promoted candidate becomes a note with no remapping.

func Extract

func Extract(ctx context.Context, client llm.Client, digest string) ([]Candidate, error)

Extract asks the model to pull qualifying write-back notes from a digest. Returns an empty slice (not an error) when there is nothing worth recording.

type Cluster

type Cluster struct {
	Rep      Candidate   `json:"rep"`      // the representative (first-seen) candidate
	Sessions []string    `json:"sessions"` // distinct sessions it appeared in
	Count    int         `json:"count"`    // distinct session count
	Members  []Candidate `json:"members"`  // all candidates in the cluster
}

Cluster is a group of similar candidates that recur across sessions: a candidate learning that shows up again and again is a SYSTEMIC issue worth a permanent fix, not a one-off write-back.

func ClusterRecurring

func ClusterRecurring(occs []Occurrence, threshold float64) []Cluster

ClusterRecurring greedily groups occurrences by title similarity (>= threshold) and returns the clusters sorted by distinct-session count, descending. A cluster spanning multiple sessions is a recurring problem.

type DigestStats

type DigestStats struct {
	Lines        int  `json:"lines"`
	UserMsgs     int  `json:"user_msgs"`
	AsstMsgs     int  `json:"asst_msgs"`
	ToolCalls    int  `json:"tool_calls"`
	HadWriteback bool `json:"had_writeback"` // the agent already called mesh_append_note/write_entity (the current algo)
	DigestChars  int  `json:"digest_chars"`
}

DigestStats describes what a transcript contained, for the benchmark baseline.

func Digest

func Digest(path string, maxChars int) (string, DigestStats, error)

Digest streams a transcript .jsonl into a compact, signal-dense summary for the extraction prompt: user requests + assistant narration + tool-call names (NOT their large outputs). Bounded to maxChars by keeping the first user request (the task) and the tail (where conclusions land). Also reports whether the agent already wrote back.

type Occurrence

type Occurrence struct {
	Cand    Candidate
	Session string
}

Occurrence is one extracted candidate tagged with the session it came from, the input to recurring-problem detection across many sessions.

Jump to

Keyboard shortcuts

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