consolidate

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package consolidate holds the feature consolidation's model calls (features/README.md, "Consolidation"): the input rendered for a repository's merge call and for one feature's split call, the reply schemas, and the validation of a reply. The host supplies its prompt versions (Prompts); Public are the published ones. It makes no call and reads no database.

Index

Constants

View Source
const (
	MaxOutputTokens     = 8192
	MaxHostOutputTokens = 32768
)

MaxOutputTokens caps a reply, reasoning included, unless the host asks for more, up to MaxHostOutputTokens: a host whose model reasons within the reply's bound and cannot be told not to may need the room.

View Source
const (
	DefaultMaxInputBytes = 200_000
	MinInputBytes        = 16 << 10
	MaxInputBytes        = 1 << 20
)

Bounds of one call's rendered input in bytes, a host's setting.

View Source
const (
	MaxTitleRunes       = 120
	MaxDescriptionRunes = 1000
)

Bounds of a part's text in a split reply; a longer one is invalid.

View Source
const (

	// MaxSplitPullRequests is the most pull requests a split call is
	// offered; a larger feature is not split.
	MaxSplitPullRequests = 200
)

Bounds of each rendered field, so no one field crowds the rest out.

View Source
const PublicVersion = "feature-consolidate-public-v1"

PublicVersion is the published prompt version.

Variables

View Source
var ErrInvalidReply = errors.New("invalid feature consolidation reply")

ErrInvalidReply is a reply that does not match its schema, names an id outside its input, or does not place every member exactly once.

View Source
var ErrTooLarge = errors.New("the consolidation input does not fit its bound")

ErrTooLarge is an input that cannot be cut down to its bound.

View Source
var Public = Prompts{
	PublicVersion: {Merge: publicMergePrompt, Split: publicSplitPrompt, Contextual: true},
}

Public are the published prompt versions: one whose merge call sees each feature's digest and its pull requests' summaries.

Functions

func Schema

func Schema(kind Kind) map[string]any

Schema is the JSON Schema of a reply of the kind, valid under OpenAI strict structured outputs.

Types

type Feature

type Feature struct {
	Title, Description string
	Digest             string
	// Withheld marks a feature whose text the repository may not read now:
	// it is rendered without its title and description.
	Withheld     bool
	Paths        []string
	PullRequests []PullRequestTitle
	// Sessions counts the connected sessions in it on their own that follow
	// no feature pull request.
	Sessions int
	// SplitFrom is the index among the features given to RenderMerge of the
	// feature a recent split created this one from, nil for none; set only
	// for a version that UsesFeatureContext.
	SplitFrom *int
}

Feature is one of a repository's features as the merge call sees it: its generated text, paths and pull request titles, never a session's prompts or decisions. Digest and the pull requests' summaries are set only for a version that UsesFeatureContext, and only as far as the repository may read them.

type Group

type Group struct {
	Survivor   int
	Duplicates []int
}

Group is a set of duplicate features of a validated merge reply, as indexes into the features given to RenderMerge: the survivor, and the duplicates that join it.

func ParseMergeReply

func ParseMergeReply(data []byte, rendered RenderedMerge) ([]Group, int, error)

ParseMergeReply decodes and validates a merge reply against the rendered input, keeping what is valid: an id outside the input is dropped (a group whose survivor is one with it), every group naming a feature the reply names more than once is dropped, and so is a group left without a duplicate. It returns the groups kept and how many of the reply's groups it dropped or cut. A reply that does not decode, or misses a field, is invalid.

type Kind

type Kind string

Kind is which of a version's two calls a request is.

const (
	// Merge proposes groups of duplicate features of one repository.
	Merge Kind = "merge"
	// Split partitions one oversized feature's pull requests.
	Split Kind = "split"
)

type Part

type Part struct {
	Title, Description string
	PullRequests       []int
}

Part is one deliverable of a validated split reply: its provisional text and its pull requests, as sorted indexes into SplitInput.PullRequests.

type Partition

type Partition struct {
	Parts  []Part
	Keeper int
}

Partition is a validated split reply. Keeper is the part that keeps the feature's id: the largest, ties to the one with the earliest pull request.

func ParseSplitReply

func ParseSplitReply(data []byte, rendered RenderedSplit) (Partition, error)

ParseSplitReply decodes and validates a split reply against the rendered input: every pull request of the input is in exactly one part, no part names an id outside it or is empty, and each has a title and a description within their bounds. Any violation invalidates the whole reply.

type Prompts

type Prompts map[string]Version

Prompts are a host's released prompt versions, by name.

func (Prompts) KnownPromptVersion

func (p Prompts) KnownPromptVersion(version string) bool

KnownPromptVersion reports whether version is a released prompt version.

func (Prompts) PromptVersions

func (p Prompts) PromptVersions() []string

PromptVersions lists the released prompt versions, sorted.

func (Prompts) Request

func (p Prompts) Request(version string, kind Kind, input string, maxOutputTokens int64) (decisions.ModelRequest, error)

Request is the call of the kind for a rendered input under prompt version version, its reply bounded by maxOutputTokens (MaxOutputTokens for 0, at most MaxHostOutputTokens).

func (Prompts) UsesFeatureContext

func (p Prompts) UsesFeatureContext(version string) bool

UsesFeatureContext reports whether version's merge call reads each feature's digest and pull request summaries (Feature.Digest, PullRequestTitle.Summary).

func (Prompts) VersionOf

func (p Prompts) VersionOf(req decisions.ModelRequest) (string, Kind, bool)

VersionOf returns the prompt version and kind req was built with by Request, so a model that sends only the input can name them to the far side.

type PullRequest

type PullRequest struct {
	Number      int32
	Title, Body string
	// Summary is what it changed, as far as the repository may read it;
	// set only for a version that UsesFeatureContext.
	Summary  string
	State    string
	OpenedAt time.Time
	Paths    []string
}

PullRequest is one of a feature's pull requests as the split call sees it.

type PullRequestTitle

type PullRequestTitle struct {
	Number  int32
	Title   string
	Summary string
}

PullRequestTitle is a pull request of a feature in the merge call.

type RenderedMerge

type RenderedMerge struct {
	Input string
	// Features lists the indexes of the rendered features: ref Fi is
	// Features[i-1].
	Features []int
	// Cut counts the features left out to keep the input within its bound.
	Cut int
	// CutSummaries and CutDigests count the pull request summaries and
	// digests left out first, before any feature is.
	CutSummaries, CutDigests int
}

RenderedMerge is the user message of a merge call.

func RenderMerge

func RenderMerge(features []Feature, maxBytes int) (RenderedMerge, error)

RenderMerge is the user message of a merge call: the features in the order given (most recently active first), every field truncated to its bound, at most maxFeatures of them and at most maxBytes long. When it is longer, pull request summaries are left out first, each feature's earliest first, in turns over the features; then digests, of the least recently active feature first; then features at the end. A feature's digest, summaries and split_from (the ref of the feature it was recently split from, when that one is rendered too) are rendered only when set, so a version that does not UsesFeatureContext renders as before.

type RenderedSplit

type RenderedSplit struct {
	Input string
	// PullRequests is how many pull requests it lists: ref Pi is the
	// (i-1)-th of SplitInput.PullRequests.
	PullRequests int
	Cut          SplitCut
}

RenderedSplit is the user message of a split call.

func RenderSplit

func RenderSplit(input SplitInput, maxBytes int) (RenderedSplit, error)

RenderSplit is the user message of a split call: the feature and every one of its pull requests, each field truncated to its bound, at most maxBytes long. When it is longer, pull request descriptions are left out first, earliest first, then their paths, then their summaries, so a large feature is still split on what its pull requests changed. A summary is rendered only when set and the feature is not withheld, so a version that does not UsesFeatureContext renders as before. A feature with more than MaxSplitPullRequests pull requests, or one that does not fit with neither, is ErrTooLarge: every pull request must be placed, so none is left out.

type SplitCut

type SplitCut struct {
	Descriptions, Paths, Summaries int
}

SplitCut counts what was left out of a split call's input.

func (SplitCut) Total

func (c SplitCut) Total() int

Total is everything left out.

type SplitInput

type SplitInput struct {
	Title, Description string
	Withheld           bool
	PullRequests       []PullRequest
}

SplitInput is one oversized feature: its text and its pull requests, earliest opened first. Withheld renders it without its text.

type Version

type Version struct {
	Merge, Split string
	// Contextual marks a version whose merge call also sees each feature's
	// digest and its pull requests' summaries.
	Contextual bool
}

Version is a released prompt version: its merge and split prompt. A released prompt is never edited; a change is a new version.

Jump to

Keyboard shortcuts

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