feat(session): add FormatHistory for worker context injection
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
38
internal/session/history.go
Normal file
38
internal/session/history.go
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user