feat(session): export PrependHistory for shared use across skills

This commit is contained in:
Mathias Bergqvist
2026-04-22 13:34:48 +02:00
parent 587c0d3b1c
commit 74547c2bdf
2 changed files with 62 additions and 0 deletions

View File

@@ -36,3 +36,21 @@ func FormatHistory(entries []Entry, excludePhase string) string {
}
return b.String()
}
// PrependHistory reads the session log for sessionID and prepends a formatted
// history block to task. Returns task unchanged if sessionID or sessionsDir is
// empty, or if no prior entries exist.
func PrependHistory(sessionsDir, sessionID, currentPhase, task string) string {
if sessionID == "" || sessionsDir == "" {
return task
}
entries, err := Read(sessionsDir, sessionID)
if err != nil || len(entries) == 0 {
return task
}
history := FormatHistory(entries, currentPhase)
if history == "" {
return task
}
return history + "\n---\n\n" + task
}