f99010fae1
CI / lint (push) Failing after 1s
CI / frontend (push) Failing after 1s
CI / scripts (push) Failing after 1s
CI / Go Test (ubuntu-latest) (push) Failing after 0s
CI / frontend-node-25 (push) Failing after 1s
CI / docs (push) Failing after 0s
CI / coverage (push) Failing after 0s
CI / e2e (push) Failing after 0s
Docker / build-and-push (push) Failing after 1s
CI / integration (push) Failing after 4m43s
CI / Go Test (windows-latest) (push) Has been cancelled
CI / Desktop Unit Tests (Windows) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Windows) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Has been cancelled
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package db
|
|
|
|
// SessionCoverageCandidate holds the current state of a session's
|
|
// token coverage flags, used as input to ComputeSessionCoverageUpdates.
|
|
type SessionCoverageCandidate struct {
|
|
ID string
|
|
TotalOutputTokens int
|
|
PeakContextTokens int
|
|
HasTotal bool
|
|
HasPeak bool
|
|
}
|
|
|
|
// SessionCoverageUpdate holds the computed coverage flags for a
|
|
// session that needs updating.
|
|
type SessionCoverageUpdate struct {
|
|
ID string
|
|
HasTotal bool
|
|
HasPeak bool
|
|
}
|
|
|
|
// ComputeSessionCoverageUpdates computes which sessions need their
|
|
// coverage flags updated based on their current state and message-level
|
|
// coverage. msgCoverage maps session ID to [hasContext, hasOutput].
|
|
// Returns only sessions whose flags would change.
|
|
func ComputeSessionCoverageUpdates(
|
|
candidates []SessionCoverageCandidate,
|
|
msgCoverage map[string][2]bool,
|
|
) []SessionCoverageUpdate {
|
|
updates := make([]SessionCoverageUpdate, 0)
|
|
for _, c := range candidates {
|
|
coverage := msgCoverage[c.ID]
|
|
newTotal := c.HasTotal || c.TotalOutputTokens != 0 || coverage[1]
|
|
newPeak := c.HasPeak || c.PeakContextTokens != 0 || coverage[0]
|
|
if newTotal == c.HasTotal && newPeak == c.HasPeak {
|
|
continue
|
|
}
|
|
updates = append(updates, SessionCoverageUpdate{
|
|
ID: c.ID,
|
|
HasTotal: newTotal,
|
|
HasPeak: newPeak,
|
|
})
|
|
}
|
|
return updates
|
|
}
|