Files
hyperguild/internal/session/history.go
Mathias Bergqvist cbef2da8de feat(session): add FormatHistory for worker context injection
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 09:40:41 +02:00

39 lines
1007 B
Go

// internal/session/history.go
package session
import (
"fmt"
"strings"
)
// FormatHistory formats prior session entries as a structured block for
// injection into a worker task prompt. Entries matching excludePhase are
// omitted (pass the current phase to avoid circular injection).
func FormatHistory(entries []Entry, excludePhase string) string {
var filtered []Entry
for _, e := range entries {
if e.Phase != excludePhase {
filtered = append(filtered, e)
}
}
if len(filtered) == 0 {
return ""
}
var b strings.Builder
b.WriteString("## Session history\n\n")
for _, e := range filtered {
b.WriteString(fmt.Sprintf("### Phase: %s\n", e.Phase))
b.WriteString(fmt.Sprintf("- Skill: %s\n", e.Skill))
b.WriteString(fmt.Sprintf("- Status: %s\n", e.FinalStatus))
if e.FilePath != "" {
b.WriteString(fmt.Sprintf("- File: %s\n", e.FilePath))
}
if e.Message != "" {
b.WriteString(fmt.Sprintf("- Summary: %s\n", e.Message))
}
b.WriteString("\n")
}
return b.String()
}