auto review
This commit is contained in:
@@ -325,9 +325,62 @@ func (m *Manager) submitReview(ctx context.Context, l *live, raw json.RawMessage
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(findings) > 0 {
|
||||
go m.forwardFindings(l.taskID, l.reviewID)
|
||||
}
|
||||
return "Review recorded. End your turn now with one line.", nil
|
||||
}
|
||||
|
||||
func (m *Manager) forwardFindings(taskID, reviewID string) {
|
||||
ctx := context.Background()
|
||||
r, err := m.store.GetReview(ctx, reviewID)
|
||||
if err != nil {
|
||||
slog.Error("load review to forward", "review", reviewID, "err", err)
|
||||
return
|
||||
}
|
||||
sessions, err := m.store.ListSessions(ctx, taskID)
|
||||
if err != nil {
|
||||
slog.Error("list sessions to forward review", "review", reviewID, "err", err)
|
||||
return
|
||||
}
|
||||
for _, s := range sessions {
|
||||
if s.State == api.AgentSessionStateCompleted {
|
||||
continue
|
||||
}
|
||||
_, err = m.Message(ctx, s.Id, "byre", findingsMessage(r), "")
|
||||
if err != nil {
|
||||
slog.Error("forward review findings", "review", reviewID, "session", s.Id, "err", err)
|
||||
return
|
||||
}
|
||||
slog.Info("review findings forwarded", "review", reviewID, "session", s.Id)
|
||||
return
|
||||
}
|
||||
slog.Info("review findings not forwarded, task has no live agent", "review", reviewID, "task", taskID)
|
||||
}
|
||||
|
||||
func findingsMessage(r api.Review) string {
|
||||
res := map[string]any{}
|
||||
if r.Result != nil {
|
||||
res = *r.Result
|
||||
}
|
||||
b := &strings.Builder{}
|
||||
fmt.Fprintf(b, "A reviewer looked at snapshot #%d of your work and raised the findings below. Reviewers can be wrong or miss context: check each one against the code and your brief, act on the ones that hold up, and in your final message say briefly which you acted on and which you're leaving and why.", r.SnapshotN)
|
||||
findings, _ := res["findings"].([]any)
|
||||
for _, f := range findings {
|
||||
fm, _ := f.(map[string]any)
|
||||
where := ""
|
||||
if p, ok := fm["path"].(string); ok && p != "" {
|
||||
where = p
|
||||
if line, ok := fm["line"].(float64); ok && line > 0 {
|
||||
where += fmt.Sprintf(":%d", int(line))
|
||||
}
|
||||
where = " (`" + where + "`)"
|
||||
}
|
||||
fmt.Fprintf(b, "\n\n**[%v] %v**%s\n\n%s", fm["severity"], fm["title"], where, strings.TrimSpace(fmt.Sprint(fm["detail"])))
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
type reviewImage struct {
|
||||
entry map[string]any
|
||||
contentType string
|
||||
|
||||
Reference in New Issue
Block a user