feat(agents): человекочитаемые вердикты аналитика, ревьюера, dev и постмортема в панель «Логи»
This commit is contained in:
@@ -104,12 +104,7 @@ func (a *Analyst) Decide(ctx context.Context, history []core.Message, draft stor
|
||||
|
||||
// 4. парсим вердикт
|
||||
verdict := opencode.ExtractVerdict(res.Stdout)
|
||||
log.Printf("analyst: verdict tail: %s", truncate(verdict, 2000))
|
||||
obj, ok := opencode.ExtractJSON(verdict)
|
||||
if ok {
|
||||
b, _ := json.Marshal(obj)
|
||||
log.Printf("analyst: extracted json: %s", truncate(string(b), 1000))
|
||||
}
|
||||
if !ok {
|
||||
return core.Decision{}, fmt.Errorf("%w: нет JSON в выводе аналитика", ErrDecodeFail)
|
||||
}
|
||||
@@ -123,6 +118,8 @@ func (a *Analyst) Decide(ctx context.Context, history []core.Message, draft stor
|
||||
return core.Decision{}, fmt.Errorf("%w: %v", ErrDecodeFail, err)
|
||||
}
|
||||
|
||||
log.Printf("analyst: вердикт: %s", truncate(formatVerdict(&ar), 2000))
|
||||
|
||||
// 5. валидация
|
||||
if err := validateResponse(&ar); err != nil {
|
||||
return core.Decision{}, fmt.Errorf("%w: %v", ErrValidation, err)
|
||||
@@ -194,4 +191,51 @@ func validateResponse(ar *AnalystResponse) error {
|
||||
return fmt.Errorf("неизвестный phase=%q", ar.Phase)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// formatVerdict собирает человекочитаемое однострочное описание вердикта
|
||||
// аналитика (без JSON-разметки) для панели «Логи».
|
||||
func formatVerdict(ar *AnalystResponse) string {
|
||||
var b strings.Builder
|
||||
b.WriteString("phase=" + ar.Phase)
|
||||
|
||||
if ar.ChatReply != "" {
|
||||
b.WriteString(", chat_reply=")
|
||||
b.WriteString(ar.ChatReply)
|
||||
}
|
||||
if len(ar.Questions) > 0 {
|
||||
b.WriteString(", questions=[")
|
||||
b.WriteString(strings.Join(ar.Questions, " | "))
|
||||
b.WriteString("]")
|
||||
}
|
||||
if ar.Title != "" {
|
||||
b.WriteString(", title=")
|
||||
b.WriteString(ar.Title)
|
||||
}
|
||||
if ar.Goal != "" {
|
||||
b.WriteString(", goal=")
|
||||
b.WriteString(ar.Goal)
|
||||
}
|
||||
if ar.Repo != "" {
|
||||
b.WriteString(", repo=")
|
||||
b.WriteString(ar.Repo)
|
||||
}
|
||||
if len(ar.Repos) > 0 {
|
||||
b.WriteString(", repos=[")
|
||||
b.WriteString(strings.Join(ar.Repos, ", "))
|
||||
b.WriteString("]")
|
||||
}
|
||||
if ar.Why != "" {
|
||||
b.WriteString(", why=")
|
||||
b.WriteString(ar.Why)
|
||||
}
|
||||
if ar.AC != "" {
|
||||
b.WriteString(", ac=")
|
||||
b.WriteString(ar.AC)
|
||||
}
|
||||
if ar.AbortReason != "" {
|
||||
b.WriteString(", abort_reason=")
|
||||
b.WriteString(ar.AbortReason)
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package analyst
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/kamelion/ratatoskr-go/internal/core"
|
||||
@@ -215,4 +216,67 @@ func TestAskEmptyReplyAndQuestions(t *testing.T) {
|
||||
if !errors.Is(err, ErrValidation) {
|
||||
t.Errorf("err = %v, want A3", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestFormatVerdict — человекочитаемое описание вердикта аналитика.
|
||||
func TestFormatVerdict(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
ar *AnalystResponse
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "propose with fields",
|
||||
ar: &AnalystResponse{
|
||||
Phase: "propose",
|
||||
Title: "Калькулятор",
|
||||
Goal: "Сделать веб-калькулятор",
|
||||
Repos: []string{"tools/calc", "tools/ui"},
|
||||
Why: "Нужен для учёта",
|
||||
AC: "Работает + - * /",
|
||||
ChatReply: "Готово!",
|
||||
},
|
||||
want: []string{
|
||||
"phase=propose",
|
||||
"chat_reply=Готово!",
|
||||
"repos=[tools/calc, tools/ui]",
|
||||
"title=Калькулятор",
|
||||
"goal=Сделать веб-калькулятор",
|
||||
"why=Нужен для учёта",
|
||||
"ac=Работает + - * /",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ask with questions",
|
||||
ar: &AnalystResponse{
|
||||
Phase: "ask",
|
||||
ChatReply: "Уточню",
|
||||
Questions: []string{"Где код?", "Какая цель?"},
|
||||
},
|
||||
want: []string{"phase=ask", "chat_reply=Уточню", "questions=[Где код? | Какая цель?]"},
|
||||
},
|
||||
{
|
||||
name: "abort with reason",
|
||||
ar: &AnalystResponse{
|
||||
Phase: "abort",
|
||||
AbortReason: "Тема не про код",
|
||||
},
|
||||
want: []string{"phase=abort", "abort_reason=Тема не про код"},
|
||||
},
|
||||
{
|
||||
name: "empty verdict",
|
||||
ar: &AnalystResponse{},
|
||||
want: []string{"phase="},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := formatVerdict(tt.ar)
|
||||
for _, w := range tt.want {
|
||||
if !strings.Contains(got, w) {
|
||||
t.Errorf("formatVerdict = %q, want contain %q", got, w)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user