diff options
Diffstat (limited to 'internal/task')
| -rw-r--r-- | internal/task/changestats.go | 47 | ||||
| -rw-r--r-- | internal/task/task.go | 13 |
2 files changed, 60 insertions, 0 deletions
diff --git a/internal/task/changestats.go b/internal/task/changestats.go new file mode 100644 index 0000000..95be8ec --- /dev/null +++ b/internal/task/changestats.go @@ -0,0 +1,47 @@ +package task + +import ( + "bufio" + "os" + "regexp" + "strconv" + "strings" +) + +// gitDiffStatRe matches git diff --stat summary lines, e.g.: +// +// "3 files changed, 50 insertions(+), 10 deletions(-)" +// "1 file changed, 5 insertions(+)" +// "1 file changed, 3 deletions(-)" +var gitDiffStatRe = regexp.MustCompile(`(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?`) + +// ParseChangestatFromOutput scans text for git diff --stat summary lines and +// returns the first match as a Changestats value. Returns nil if no match found. +func ParseChangestatFromOutput(output string) *Changestats { + scanner := bufio.NewScanner(strings.NewReader(output)) + for scanner.Scan() { + line := scanner.Text() + if m := gitDiffStatRe.FindStringSubmatch(line); m != nil { + cs := &Changestats{} + cs.FilesChanged, _ = strconv.Atoi(m[1]) + if m[2] != "" { + cs.LinesAdded, _ = strconv.Atoi(m[2]) + } + if m[3] != "" { + cs.LinesRemoved, _ = strconv.Atoi(m[3]) + } + return cs + } + } + return nil +} + +// ParseChangestatFromFile reads a log file and extracts the first git diff stat +// summary it finds. Returns nil if the file cannot be read or contains no match. +func ParseChangestatFromFile(path string) *Changestats { + data, err := os.ReadFile(path) + if err != nil { + return nil + } + return ParseChangestatFromOutput(string(data)) +} diff --git a/internal/task/task.go b/internal/task/task.go index 69da5f3..6a9d1db 100644 --- a/internal/task/task.go +++ b/internal/task/task.go @@ -48,6 +48,19 @@ type RetryConfig struct { Backoff string `yaml:"backoff" json:"backoff"` // "linear", "exponential" } +// GitCommit represents a single git commit created during a task execution. +type GitCommit struct { + Hash string `json:"hash"` + Message string `json:"message"` +} + +// Changestats records file/line change metrics from an agent execution. +type Changestats struct { + FilesChanged int `json:"files_changed"` + LinesAdded int `json:"lines_added"` + LinesRemoved int `json:"lines_removed"` +} + // Interaction records a single question/answer exchange between an agent and the user. type Interaction struct { QuestionText string `json:"question_text"` |
