promptstats

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package promptstats tracks per-task prompt outcomes to learn which prompt patterns correlate with success vs failure. Records are appended to .cloop/prompt-stats.jsonl as JSONL entries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdaptiveHint

func AdaptiveHint(records []Record, taskTitle string) string

AdaptiveHint returns a short advisory string to prepend to a prompt based on historical outcomes for tasks with similar titles. Returns "" when there is no relevant history (< 2 matching records).

func Append

func Append(workDir string, rec Record) error

Append writes a single record to the JSONL stats file, creating the file and parent directory as needed.

func FeedbackHint

func FeedbackHint(records []FeedbackRecord, taskTitle string) string

FeedbackHint returns a short advisory string derived from human ratings of similar tasks. Returns "" when there are fewer than 2 matching records. High-rated tasks (4-5) indicate an approach that worked well; low-rated ones (1-2) flag patterns to avoid.

func HashPrompt

func HashPrompt(prompt string) string

HashPrompt returns a 12-char hex prefix of the SHA-256 of the prompt. This is used as a compact fingerprint for matching similar prompts.

Types

type FeedbackRecord

type FeedbackRecord struct {
	TaskID    int
	TaskTitle string
	Rating    int // 1-5
	Comment   string
}

FeedbackRecord is a minimal view of pkg/feedback.Record used here to avoid an import cycle. Callers should pass feedback records cast to this type.

type HashStats

type HashStats struct {
	Hash    string
	Total   int
	Done    int
	Failed  int
	Skipped int
	TotalMs int64
}

HashStats aggregates outcomes for a single prompt hash.

func TopPerforming

func TopPerforming(s Summary, minTotal int) []*HashStats

TopPerforming returns HashStats sorted by success rate descending, limited to hashes with at least minTotal executions.

func (HashStats) AvgDurMs

func (h HashStats) AvgDurMs() int64

AvgDurMs returns the average duration in milliseconds.

func (HashStats) FailureRate

func (h HashStats) FailureRate() float64

FailureRate returns the fraction of executions that failed (0.0 – 1.0).

func (HashStats) SuccessRate

func (h HashStats) SuccessRate() float64

SuccessRate returns the fraction of executions that succeeded (0.0 – 1.0).

type Record

type Record struct {
	TaskTitle  string `json:"task_title"`
	PromptHash string `json:"prompt_hash"`
	Outcome    string `json:"outcome"`     // "done", "failed", "skipped"
	DurationMs int64  `json:"duration_ms"` // wall-clock ms for the task
}

Record is a single prompt outcome entry written after a task completes.

func Load

func Load(workDir string) ([]Record, error)

Load reads all records from the stats file. Returns nil, nil when the file does not exist yet.

type Summary

type Summary struct {
	Total   int
	Done    int
	Failed  int
	Skipped int
	ByHash  map[string]*HashStats
}

Summary aggregates all records into per-hash statistics.

func Summarize

func Summarize(records []Record) Summary

Summarize aggregates records into a Summary.

Jump to

Keyboard shortcuts

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