feat(session): add FormatHistory for worker context injection

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mathias Bergqvist
2026-04-19 09:28:52 +02:00
parent b493651c26
commit cbef2da8de
2 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
// 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()
}