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()
|
||||
}
|
||||
41
internal/session/history_test.go
Normal file
41
internal/session/history_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// internal/session/history_test.go
|
||||
package session_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mathiasbq/supervisor/internal/session"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFormatHistoryEmpty(t *testing.T) {
|
||||
result := session.FormatHistory(nil, "")
|
||||
assert.Equal(t, "", result)
|
||||
}
|
||||
|
||||
func TestFormatHistoryFormatsEntries(t *testing.T) {
|
||||
entries := []session.Entry{
|
||||
{
|
||||
Skill: "tdd", Phase: "red", FinalStatus: "pass",
|
||||
FilePath: "internal/foo/foo_test.go",
|
||||
Message: "wrote failing test for Foo",
|
||||
Timestamp: time.Now(),
|
||||
},
|
||||
}
|
||||
result := session.FormatHistory(entries, "")
|
||||
assert.Contains(t, result, "## Session history")
|
||||
assert.Contains(t, result, "Phase: red")
|
||||
assert.Contains(t, result, "wrote failing test for Foo")
|
||||
assert.Contains(t, result, "internal/foo/foo_test.go")
|
||||
}
|
||||
|
||||
func TestFormatHistoryExcludesCurrentPhase(t *testing.T) {
|
||||
entries := []session.Entry{
|
||||
{Skill: "tdd", Phase: "red", Message: "red done", FinalStatus: "pass"},
|
||||
{Skill: "tdd", Phase: "green", Message: "green done", FinalStatus: "pass"},
|
||||
}
|
||||
result := session.FormatHistory(entries, "green")
|
||||
assert.Contains(t, result, "red done")
|
||||
assert.NotContains(t, result, "green done")
|
||||
}
|
||||
Reference in New Issue
Block a user