Expose storage usage and safe persisted age or size retention

This commit is contained in:
2026-11-06 21:34:55 +00:00
parent aa19c82156
commit 6abc309009
19 changed files with 1309 additions and 12 deletions
+4
View File
@@ -127,6 +127,10 @@ type PipelineSummary struct {
// are optional so older peers ignore them. See search.go for the per-type payloads
// and the ranking/kind/bound vocabulary.
type Message struct {
Storage *StorageOverview `json:"storage,omitempty"`
StoragePolicy *StoragePolicy `json:"storage_policy,omitempty"`
StorageCleanup *StorageCleanupResult `json:"storage_cleanup,omitempty"`
StorageCleanupToken string `json:"storage_cleanup_token,omitempty"`
Schedule *SavedSchedule `json:"schedule,omitempty"`
Schedules []SavedSchedule `json:"schedules,omitempty"`
ScheduleID int64 `json:"schedule_id,omitempty"`
+4 -3
View File
@@ -32,9 +32,10 @@ const (
// the deleted runs as measured immediately before deletion. All three are
// always present.
type RunsDeletedResult struct {
Deleted []int64 `json:"deleted"`
Refused []RunDeleteRefusal `json:"refused"`
FreedBytes int64 `json:"freed_bytes"`
RemainingFileBytes int64 `json:"remaining_file_bytes,omitempty"`
Deleted []int64 `json:"deleted"`
Refused []RunDeleteRefusal `json:"refused"`
FreedBytes int64 `json:"freed_bytes"`
}
// RunDeleteRefusal is one requested run id delete_runs did not remove.
+79
View File
@@ -0,0 +1,79 @@
package protocol
import "fmt"
const (
GetStorage = "get_storage"
SetStoragePolicy = "set_storage_policy"
PreviewStorageCleanup = "preview_storage_cleanup"
ApplyStorageCleanup = "apply_storage_cleanup"
StorageReply = "storage"
StoragePolicySaved = "storage_policy_saved"
StorageCleanupPreview = "storage_cleanup_preview"
StorageCleanupApplied = "storage_cleanup_applied"
)
// StoragePolicy is a server-wide opt-in policy. Age expiry and the size target
// are independent triggers; protected work is never removed to meet a target.
type StoragePolicy struct {
Enabled bool `json:"enabled"`
MaxAgeDays int `json:"max_age_days"`
MaxBytes int64 `json:"max_bytes"`
IncludeWorktrees bool `json:"include_worktrees"`
}
func (p StoragePolicy) Validate() error {
if p.MaxAgeDays < 0 || p.MaxAgeDays > 36500 {
return fmt.Errorf("max_age_days must be between 0 and 36500")
}
if p.MaxBytes < 0 || p.MaxBytes > 1<<50 {
return fmt.Errorf("max_bytes must be between 0 and 1125899906842624")
}
if p.Enabled && p.MaxAgeDays == 0 && p.MaxBytes == 0 {
return fmt.Errorf("automatic retention requires an age or size limit")
}
return nil
}
type StorageCategory struct {
ID string `json:"id"`
Label string `json:"label"`
Path string `json:"path,omitempty"`
Bytes int64 `json:"bytes"`
Files int64 `json:"files"`
Partial bool `json:"partial,omitempty"`
Error string `json:"error,omitempty"`
}
type StorageOverview struct {
Measurement string `json:"measurement"`
TotalBytes int64 `json:"total_bytes"`
Categories []StorageCategory `json:"categories"`
Policy StoragePolicy `json:"policy"`
MeasuredAt string `json:"measured_at"`
Partial bool `json:"partial"`
Warnings []string `json:"warnings,omitempty"`
AutomaticIntervalSeconds int `json:"automatic_interval_seconds"`
}
type StorageCleanupItem struct {
Kind string `json:"kind"`
ID string `json:"id"`
Path string `json:"path,omitempty"`
Bytes int64 `json:"bytes"`
Reason string `json:"reason,omitempty"`
Protected bool `json:"protected"`
}
type StorageCleanupResult struct {
Policy StoragePolicy `json:"policy"`
TotalBytes int64 `json:"total_bytes"`
ReclaimableBytes int64 `json:"reclaimable_bytes"`
TargetBytes int64 `json:"target_bytes"`
TargetReached bool `json:"target_reached"`
CandidateCount int `json:"candidate_count"`
ProtectedCount int `json:"protected_count"`
Items []StorageCleanupItem `json:"items"`
PreviewToken string `json:"preview_token,omitempty"`
RemovedCount int `json:"removed_count"`
RemovedBytes int64 `json:"removed_bytes"`
Applied bool `json:"applied"`
Errors []string `json:"errors,omitempty"`
}