trace

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package trace correlates recent git commits with PM plan tasks using an AI provider. It walks git log, sends commit messages + task list to the provider, and returns a structured mapping of commit→task with confidence levels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildPrompt

func BuildPrompt(commits []Commit, tasks []*pm.Task) string

BuildPrompt constructs the AI prompt for commit→task mapping.

func WriteTraceJSON

func WriteTraceJSON(workDir string, tm *TraceMap) error

WriteTraceJSON persists the trace map to .cloop/trace.json.

The write is atomic: data is staged in a sibling .tmp file, fsynced, chmod'd, then renamed into place. Without this, a crash mid-write or ENOSPC would leave trace.json corrupted, which would silently break `cloop status` (which calls LastLinkedCommit on every invocation) and any tooling that loads the commit→task mapping.

Types

type Commit

type Commit struct {
	Hash    string `json:"hash"`
	Subject string `json:"subject"`
}

Commit holds a parsed git log entry.

func GitLog

func GitLog(workDir string, limit int, since string) ([]Commit, error)

GitLog returns the most recent commits (up to limit) from workDir. If since is non-empty it is passed as --since to git log.

type Confidence

type Confidence string

Confidence is the AI-rated match quality for a commit→task pairing.

const (
	ConfidenceHigh   Confidence = "high"
	ConfidenceMedium Confidence = "medium"
	ConfidenceLow    Confidence = "low"
	ConfidenceNone   Confidence = "none"
)

type TraceEntry

type TraceEntry struct {
	Hash             string     `json:"hash"`
	Subject          string     `json:"subject"`
	MatchedTaskID    int        `json:"matched_task_id"`    // 0 = no match
	MatchedTaskTitle string     `json:"matched_task_title"` // empty = no match
	Confidence       Confidence `json:"confidence"`
}

TraceEntry links a single commit to a task (or indicates no match).

func LastLinkedCommit

func LastLinkedCommit(workDir string) *TraceEntry

LastLinkedCommit returns the most recent commit entry that was matched to a task, or nil if none found. Used by `cloop status`.

type TraceMap

type TraceMap struct {
	GeneratedAt time.Time    `json:"generated_at"`
	Entries     []TraceEntry `json:"entries"`
}

TraceMap is the complete mapping for a run.

func LoadTraceJSON

func LoadTraceJSON(workDir string) (*TraceMap, error)

LoadTraceJSON reads the persisted trace map from .cloop/trace.json. Returns nil without error when the file does not exist.

On parse failure (zero-byte file from a torn pre-atomicfile write, schema drift, manual edit gone wrong) the corrupt trace.json is quarantined aside as trace.json.corrupt-<unix> and (nil, nil) is returned. The trace map is a derived index of commit→task links; `cloop status`, LastLinkedCommit, and similar callers all already handle the "no trace data yet" case, so returning empty is strictly better than refusing every status query until the user manually deletes the corrupt file.

func Run

func Run(ctx context.Context, prov provider.Provider, model string, workDir string, limit int, since string) (*TraceMap, error)

Run orchestrates the full trace pipeline: collect commits, call AI, parse, return.

Jump to

Keyboard shortcuts

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