Add RecentSessions reader over the audit chain

Exposes the last n session summaries (oldest-first) for the reviewer to
read as recent-history context. Missing/empty chain or n<=0 yields nil.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-01 09:26:57 -04:00
parent e4e34b092c
commit 25f56b3c71
2 changed files with 61 additions and 0 deletions
+19
View File
@@ -74,6 +74,25 @@ func readSummaries(path string) ([]SessionSummary, error) {
return out, sc.Err()
}
// RecentSessions returns up to n most-recent summaries from the audit chain in
// oldest-first order. A missing/empty chain or n <= 0 yields (nil, nil).
func RecentSessions(path string, n int) ([]SessionSummary, error) {
if n <= 0 {
return nil, nil
}
all, err := readSummaries(path)
if err != nil {
return nil, err
}
if len(all) == 0 {
return nil, nil
}
if len(all) > n {
all = all[len(all)-n:]
}
return all, nil
}
// AppendSession links s onto the chain (genesis prev_hash = 64 zeros), assigns
// the next contiguous Seq, computes its Hash, and appends one JSON line with an
// fsync.