cache

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: GPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	FormatJSON             = "json"
	FormatMarkdownFallback = "markdown-fallback"
	// FormatPlainText is the marker for cache entries written by
	// PlainTextEmitter providers (CLI-based). The Content is the
	// host CLI's already-formatted output — no JSON parse, no
	// retry-once, no degrade warning. Renderer emits Content verbatim.
	FormatPlainText = "plain-text"
)

Format values for cache.Result.Format. Kept as package-level constants so callers (CLI, renderer) avoid stringly-typed comparisons.

View Source
const DefaultTTL = 7 * 24 * time.Hour
View Source
const SchemaVersion = 1

Variables

This section is empty.

Functions

func Compute

func Compute(args ComputeArgs) string

Compute returns the deterministic SHA-256 key (lowercase hex) for the cache lookup. The schema version is folded in so a future bump invalidates every existing entry without touching disk.

func EnsureGitignore

func EnsureGitignore(repoRoot string) (bool, error)

EnsureGitignore appends `.commitbrief/` to the repo's .gitignore if not already present. Idempotent: a file that already contains the entry is left untouched. Returns true if the file was modified.

Types

type Cache

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

func Open

func Open(opts Options) (*Cache, error)

func (*Cache) Delete

func (c *Cache) Delete(key string) error

func (*Cache) Dir

func (c *Cache) Dir() string

func (*Cache) Get

func (c *Cache) Get(key string) (Entry, bool)

func (*Cache) Put

func (c *Cache) Put(key string, entry Entry) error

type ComputeArgs

type ComputeArgs struct {
	Diff         string
	SystemPrompt string
	Provider     string
	Model        string
	Lang         string
}

type Entry

type Entry struct {
	Version   int       `json:"version"`
	CreatedAt time.Time `json:"created_at"`
	TTL       int64     `json:"ttl"`
	Key       KeyMeta   `json:"key"`
	Result    Result    `json:"result"`
}

func (Entry) Expired

func (e Entry) Expired() bool

func (Entry) ExpiredAt

func (e Entry) ExpiredAt(now time.Time) bool

type KeyMeta

type KeyMeta struct {
	DiffHash         string `json:"diff_hash"`
	SystemPromptHash string `json:"system_prompt_hash"`
	Model            string `json:"model"`
	Provider         string `json:"provider"`
	Lang             string `json:"lang"`
}

type Options

type Options struct {
	Dir string

	// RepoRoot, if non-empty, enables auto-add of `.commitbrief/` to the
	// repo's .gitignore on the first successful Put.
	RepoRoot string

	// TTL controls how long an entry is considered fresh. Zero falls back
	// to DefaultTTL (7 days).
	TTL time.Duration

	// Now overrides time.Now (test injection); production callers leave it nil.
	Now func() time.Time
}

type Result

type Result struct {
	Content string `json:"content"`
	Tokens  Tokens `json:"tokens"`

	// Format records which renderer path the cached entry should take on
	// replay. Values (ADR-0014 §4):
	//   "json"               — Content is the structured-findings JSON; the
	//                          renderer parses it as usual.
	//   "markdown-fallback"  — provider produced unparseable output; the
	//                          retry also failed. The cached Content is the
	//                          raw text and the renderer skips the parse
	//                          step entirely (no warning re-emitted).
	// Empty string is treated as "json" for backwards compatibility with
	// pre-ADR-0014 cache entries; they'll be invalidated next request
	// anyway via the system-prompt SHA change (ADR-0014 §6).
	Format string `json:"format,omitempty"`
}

type Tokens

type Tokens struct {
	Input  int `json:"input"`
	Output int `json:"output"`
	Cached int `json:"cached"`
}

Jump to

Keyboard shortcuts

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