Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts. Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation. Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package seheweit
|
|
|
|
import "time"
|
|
|
|
const (
|
|
ResourceEventID = "builtin.resource.sample"
|
|
ResourceEventType = "resource.sample"
|
|
RetentionDays = 7
|
|
MaxHistoryPoints = 361
|
|
)
|
|
|
|
// HistoryWindow describes the existing inclusive, epoch-aligned sample query.
|
|
// Persistence chooses the most recently inserted sample in each bucket, not an
|
|
// average, a peak or necessarily the largest timestamp in out-of-order data.
|
|
type HistoryWindow struct {
|
|
FromMS int64
|
|
ToMS int64
|
|
BucketMS int64
|
|
}
|
|
|
|
func Window(hours int, now time.Time) HistoryWindow {
|
|
if hours < 1 {
|
|
hours = 1
|
|
}
|
|
if hours > RetentionDays*24 {
|
|
hours = RetentionDays * 24
|
|
}
|
|
span := int64(time.Duration(hours) * time.Hour / time.Millisecond)
|
|
bucket := span / (MaxHistoryPoints - 1)
|
|
if bucket < int64(time.Minute/time.Millisecond) {
|
|
bucket = int64(time.Minute / time.Millisecond)
|
|
}
|
|
return HistoryWindow{FromMS: now.UnixMilli() - span, ToMS: now.UnixMilli(), BucketMS: bucket}
|
|
}
|
|
|
|
// RetentionCutoff is inclusive: only samples strictly older are expired.
|
|
func RetentionCutoff(atMS int64) int64 {
|
|
return atMS - int64(RetentionDays*24*time.Hour/time.Millisecond)
|
|
}
|