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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user