taste

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package taste implements a learning system that observes user coding preferences and builds a style profile over time to improve agent output alignment.

Index

Constants

View Source
const (
	NamingCamelCase  = "camelCase"
	NamingSnakeCase  = "snake_case"
	NamingPascalCase = "PascalCase"
	NamingKebabCase  = "kebab-case"
)

Naming style constants.

View Source
const (
	ErrorSentinel = "sentinel"
	ErrorWrapped  = "wrapped"
	ErrorPanic    = "panic"
	ErrorCustom   = "custom_type"
)

Error style constants.

View Source
const (
	AbstractionInlined   = "inlined"
	AbstractionExtracted = "extracted"
)

Abstraction level constants.

View Source
const (
	TestTableDriven = "table_driven"
	TestSubtests    = "subtests"
	TestAssertLib   = "assert_lib"
	TestPlain       = "plain"
)

Test style constants.

View Source
const (
	CategoryNaming        = "naming"
	CategoryComments      = "comments"
	CategoryErrorHandling = "error_handling"
	CategoryAbstraction   = "abstraction"
	CategoryTesting       = "testing"
	CategoryFormatting    = "formatting"
)

Category constants for preference tracking.

View Source
const DefaultDecay = 0.95

DefaultDecay is the standard exponential decay rate for signals.

Variables

This section is empty.

Functions

func AllCategories

func AllCategories() []string

AllCategories returns all supported preference categories.

func AnalyzeCode

func AnalyzeCode(code string) map[string]string

AnalyzeCode runs all detectors on a code sample and returns detected signals.

func DetectAbstractionLevel

func DetectAbstractionLevel(code string) string

DetectAbstractionLevel estimates if code prefers inlining or extraction.

func DetectCommentDensity

func DetectCommentDensity(code string) float64

DetectCommentDensity returns the ratio of comment lines to total non-empty lines.

func DetectErrorPattern

func DetectErrorPattern(code string) string

DetectErrorPattern analyzes Go/Python/JS code to categorize error handling style.

func DetectLanguage

func DetectLanguage(code string) string

DetectLanguage attempts to identify the programming language from code content.

func DetectNamingStyle

func DetectNamingStyle(code string) string

DetectNamingStyle analyzes code to determine the predominant naming convention.

func DetectTestStyle

func DetectTestStyle(code string) string

DetectTestStyle analyzes test code to determine testing patterns.

Types

type Collector

type Collector struct {
	// contains filtered or unexported fields
}

Collector observes agent output vs user final version and extracts style signals.

func NewCollector

func NewCollector(profile *Profile) *Collector

NewCollector creates a new taste collector bound to a profile.

func (*Collector) Cleanup

func (c *Collector) Cleanup(maxAge time.Duration)

Cleanup removes proposals older than the given duration.

func (*Collector) PendingCount

func (c *Collector) PendingCount() int

PendingCount returns the number of proposals awaiting resolution.

func (*Collector) RecentSignals

func (c *Collector) RecentSignals(n int) []DiffSignal

RecentSignals returns the diff signals from the last N interactions.

func (*Collector) RecordEdit

func (c *Collector) RecordEdit(id string, final string)

RecordEdit stores what the user actually used and computes diff signals.

func (*Collector) RecordOutcome

func (c *Collector) RecordOutcome(id string, outcome Outcome)

RecordOutcome marks the user's decision on a proposal.

func (*Collector) RecordProposal

func (c *Collector) RecordProposal(id string, proposed string)

RecordProposal stores what the agent suggested.

type DiffSignal

type DiffSignal struct {
	Category string
	Proposed string
	Actual   string
}

DiffSignal represents a detected style difference between proposed and final code.

func ComputeDiff

func ComputeDiff(proposed, final string) []DiffSignal

ComputeDiff analyzes the nature of changes between proposed and final code.

type Hooks

type Hooks struct {
	// contains filtered or unexported fields
}

Hooks provides integration points for the engine/REPL loop to feed signals to the taste collector.

func NewHooks

func NewHooks(projectID string, store *Store) (*Hooks, error)

NewHooks creates a taste hooks instance bound to a project.

func (*Hooks) Collector

func (h *Hooks) Collector() *Collector

Collector returns the underlying collector.

func (*Hooks) OnCodeAccepted

func (h *Hooks) OnCodeAccepted(sessionID, proposedCode string)

OnCodeAccepted records that the user accepted the proposed code without edits.

func (*Hooks) OnCodeEdited

func (h *Hooks) OnCodeEdited(sessionID, proposedCode, finalCode string)

OnCodeEdited records that the user modified the proposed code.

func (*Hooks) OnCodeProposed

func (h *Hooks) OnCodeProposed(sessionID, proposedCode string) string

OnCodeProposed records a new code proposal from the agent.

func (*Hooks) OnCodeRejected

func (h *Hooks) OnCodeRejected(sessionID, proposedCode string)

OnCodeRejected records that the user rejected the proposed code entirely.

func (*Hooks) Profile

func (h *Hooks) Profile() *Profile

Profile returns the current taste profile.

func (*Hooks) PromptContext

func (h *Hooks) PromptContext() string

PromptContext returns the current taste profile as a system prompt fragment.

type Outcome

type Outcome int

Outcome represents the user's response to a code proposal.

const (
	OutcomeAccept Outcome = iota
	OutcomeEdit
	OutcomeReject
)

func (Outcome) String

func (o Outcome) String() string

type Profile

type Profile struct {
	Preferences map[string]Signal `json:"preferences"`
	ProjectID   string            `json:"project_id,omitempty"`
	Version     int               `json:"version"`
	CreatedAt   time.Time         `json:"created_at"`
	UpdatedAt   time.Time         `json:"updated_at"`
	// contains filtered or unexported fields
}

Profile holds a user's coding style preferences, keyed by category.

func NewProfile

func NewProfile(projectID string) *Profile

NewProfile creates a fresh empty profile.

func (*Profile) Get

func (p *Profile) Get(category string) Signal

Get returns the current preference signal for a category.

func (*Profile) Merge

func (p *Profile) Merge(other *Profile)

Merge blends another profile into this one, useful for team taste sharing.

func (*Profile) Reset

func (p *Profile) Reset()

Reset clears all preferences.

func (*Profile) Summary

func (p *Profile) Summary() string

Summary returns a human-readable summary of the profile.

func (*Profile) ToPromptContext

func (p *Profile) ToPromptContext() string

ToPromptContext serializes the top preferences into a system prompt fragment.

func (*Profile) Update

func (p *Profile) Update(category string, signal Signal)

Update records a new signal for a category using exponential moving average with decay.

type Proposal

type Proposal struct {
	ID         string
	Proposed   string
	Final      string
	Outcome    Outcome
	Signals    []DiffSignal
	RecordedAt time.Time
}

Proposal tracks what the agent proposed and how the user responded.

type Signal

type Signal struct {
	Value       string    `json:"value"`
	Confidence  float64   `json:"confidence"`
	SampleCount int       `json:"sample_count"`
	LastUpdated time.Time `json:"last_updated"`
	Decay       float64   `json:"decay"`
}

Signal represents a single preference observation with confidence tracking.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store manages file-based persistence for taste profiles at ~/.hawk/taste/.

func NewStore

func NewStore(baseDir string) (*Store, error)

NewStore creates a store rooted at the given base directory. If baseDir is empty, it defaults to ~/.hawk/taste/.

func (*Store) Delete

func (s *Store) Delete(projectID string) error

Delete removes a stored profile.

func (*Store) Export

func (s *Store) Export(projectID string) ([]byte, error)

Export serializes the current profile for transfer (push/pull).

func (*Store) Import

func (s *Store) Import(data []byte) error

Import loads a profile from exported data.

func (*Store) List

func (s *Store) List() ([]string, error)

List returns all project IDs that have stored profiles.

func (*Store) Load

func (s *Store) Load(projectID string) (*Profile, error)

Load reads a profile for the given project ID.

func (*Store) Save

func (s *Store) Save(projectID string, profile *Profile) error

Save persists a profile for the given project ID.

Jump to

Keyboard shortcuts

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