Documentation
¶
Overview ¶
Package discover holds feature discovery's pure parts (features/README.md, "Discovery"): the taxonomy a discovery task replies with and its bounds, the pull request history digest the task reads, the task's prompt and reply schema, and the path score a seeded feature is offered by. It runs no task and reads no database.
Index ¶
- Constants
- Variables
- func Check(document []byte) string
- func ComposePrompt(frame, singlePrompt string) (string, error)
- func HistoryDigest(repository string, pulls []HistoryPullRequest) []byte
- func HistoryDigestWithin(repository string, pulls []HistoryPullRequest, maxBytes int) []byte
- func HistoryPathPrefixes(paths []string) []string
- func PathScores(seeds [][]string, paths []string) []float64
- func Under(path, prefix string) bool
- func ValidateTaxonomyFeatures(features []TaxonomyFeature) error
- type FeatureSeed
- type FeatureSeeds
- type FeatureTaxonomy
- type HistoryDigestHeader
- type HistoryDigestLine
- type HistoryDigestTrimmed
- type HistoryPullRequest
- type Reply
- type TaxonomyFeature
Constants ¶
const ( MaxTaxonomyFeatures = 300 MaxTaxonomyTitleRunes = 120 MaxTaxonomyDescriptionRunes = 1000 )
Bounds of a taxonomy. A feature's text has the bounds of a feature the assigner starts.
const (
HistoryDigestMaxBytes = 4 << 20
)
The history digest is a repository's pull request history as feature discovery reads it: JSON Lines, a header then one pull request per line with the files it touched, oldest first. The agent searches it as a file, so its cap only bounds it: HistoryDigestMaxBytes.
const PublicVersion = "feature-discover-public-v1"
PublicVersion is the published discovery prompt's version, composed from assign.PublicVersion.
const TaxonomySchemaVersion = 1
TaxonomySchemaVersion is the schema version of FeatureTaxonomy and FeatureSeeds.
Variables ¶
var ErrInvalidTaxonomy = errors.New("invalid feature taxonomy")
ErrInvalidTaxonomy is a taxonomy that does not parse, belongs to another repository or is over its bounds.
var PublicPrompt = func() string { single, _ := assign.Public.Prompt(assign.PublicVersion) prompt, err := ComposePrompt(publicFrame, single) if err != nil { panic(err) } return prompt }()
PublicPrompt is the published discovery prompt.
var Schema = json.RawMessage(`{"type":"object","additionalProperties":false,"required":["features"],"properties":{"features":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["title","description","paths","examples"],"properties":{"title":{"type":"string"},"description":{"type":"string"},"paths":{"type":"array","items":{"type":"string"}},"examples":{"type":"array","items":{"type":"integer"}}}}}}}`)
Schema is the discovery reply's schema: the taxonomy's features.
Functions ¶
func Check ¶
Check is the task's check of a reply the schema accepts: the taxonomy's bounds. It returns the findings, empty for a valid reply.
func ComposePrompt ¶
ComposePrompt is a discovery prompt: frame with the definition of a feature of the single-item assigner prompt singlePrompt, cut out unchanged, in place of {{definition}}, so discovery and assignment group at the same level.
func HistoryDigest ¶
func HistoryDigest(repository string, pulls []HistoryPullRequest) []byte
HistoryDigest is the history digest of pulls, in their order, within HistoryDigestMaxBytes.
func HistoryDigestWithin ¶
func HistoryDigestWithin(repository string, pulls []HistoryPullRequest, maxBytes int) []byte
HistoryDigestWithin is the history digest of pulls within maxBytes: over it, it drops every branch, then replaces each pull request's files with the directories holding most of them from the oldest on, then drops the oldest pull requests, each until it fits.
func HistoryPathPrefixes ¶
HistoryPathPrefixes are the directories, three levels deep and ending in "/", holding the most of paths, most first, at most five; a top-level file is its own.
func PathScores ¶
PathScores are the path scores of seeds, each seed's taxonomy path prefixes, for an item touching paths: the sum, over the item's distinct paths under a seed's prefixes, of one over the number of seeds holding the path.
func Under ¶
Under reports whether a repository path is under a taxonomy path prefix: the prefix itself or in the folder it names, with or without a trailing "/".
func ValidateTaxonomyFeatures ¶
func ValidateTaxonomyFeatures(features []TaxonomyFeature) error
ValidateTaxonomyFeatures checks a taxonomy's features against its bounds.
Types ¶
type FeatureSeed ¶
type FeatureSeed struct {
FeatureID string `json:"feature_id"`
Entry int `json:"entry"`
Paths []string `json:"paths"`
}
FeatureSeed is a feature seeded from the taxonomy's feature at Entry (its index in the taxonomy's features), with that feature's paths.
type FeatureSeeds ¶
type FeatureSeeds struct {
SchemaVersion int `json:"schema_version"`
TaxonomyID string `json:"taxonomy_id"`
Seeds []FeatureSeed `json:"seeds"`
}
FeatureSeeds is the seed mapping of a version: the features a build seeded it with from a taxonomy. A seeded feature's paths are kept with the mapping only, never with the feature.
type FeatureTaxonomy ¶
type FeatureTaxonomy struct {
SchemaVersion int `json:"schema_version"`
RepositoryID string `json:"repository_id"`
// Revision is the commit the checkout was at.
Revision string `json:"revision"`
CreatedAt time.Time `json:"created_at"`
Features []TaxonomyFeature `json:"features"`
}
FeatureTaxonomy is a taxonomy document: a repository's features as discovered from its code, which a build or rebuild seeds its new version with.
func ParseFeatureTaxonomy ¶
func ParseFeatureTaxonomy(data []byte, repositoryID string) (FeatureTaxonomy, error)
ParseFeatureTaxonomy decodes a taxonomy of repositoryID and validates it.
func (FeatureTaxonomy) Validate ¶
func (t FeatureTaxonomy) Validate(repositoryID string) error
Validate checks that the taxonomy is of repositoryID and within its bounds.
type HistoryDigestHeader ¶
type HistoryDigestHeader struct {
Repository string `json:"repository"`
PullRequests int `json:"pull_requests"`
Merged int `json:"merged"`
Open int `json:"open"`
Trimmed HistoryDigestTrimmed `json:"trimmed"`
}
HistoryDigestHeader is the digest's first line.
type HistoryDigestLine ¶
type HistoryDigestLine struct {
N int32 `json:"n"`
Opened string `json:"opened"`
State string `json:"state"`
Title string `json:"title"`
Branch string `json:"branch,omitempty"`
Paths []string `json:"paths"`
}
HistoryDigestLine is one pull request's line.
type HistoryDigestTrimmed ¶
type HistoryDigestTrimmed struct {
Branches int `json:"branches"`
Paths int `json:"paths"`
PullRequests int `json:"pull_requests"`
}
HistoryDigestTrimmed counts the pull requests each trimming step changed.
type HistoryPullRequest ¶
type HistoryPullRequest struct {
Number int32
Opened time.Time
Merged bool
Title string
Branch string
Paths []string
}
HistoryPullRequest is a pull request as the history digest lists it, with the paths its commits touch.
type Reply ¶
type Reply struct {
Features []TaxonomyFeature `json:"features"`
}
Reply is a discovery reply.
type TaxonomyFeature ¶
type TaxonomyFeature struct {
Title string `json:"title"`
Description string `json:"description"`
Paths []string `json:"paths"`
Examples []int32 `json:"examples"`
}
TaxonomyFeature is one discovered feature: its text, the path prefixes its code lives under (Under), and pull requests that are examples of its work.