core

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Reset = colorReset
	Cyan  = colorCyan
	Gray  = colorGray
	Bold_ = colorBold
)

Exported ANSI codes for callers that build their own colored output.

View Source
const AnalyzerTimeoutSeconds = 180

AnalyzerTimeoutSeconds bounds each analyzer. Repo scans over large source trees are the slowest domain, so this leaves headroom above their typical runtime while still guarding against a runaway walk.

View Source
const DefaultMinSizeMB = 50

DefaultMinSizeMB is the minimum file size (in MB) to flag in downloads

Variables

View Source
var (
	// HomeDir is the current user's home directory
	HomeDir string

	// RepoRoots are directories to scan for node_modules, .venv, __pycache__
	RepoRoots []string

	// BrowserCachePaths maps browser name to its cache directory
	BrowserCachePaths map[string]string

	// LogDirs are directories containing log files
	LogDirs []string

	// DownloadDirs are directories to scan for large/old downloads
	DownloadDirs []string

	// AppSupportDir is ~/Library/Application Support
	AppSupportDir string

	// OllamaModelsDir is where Ollama stores downloaded LLM models
	OllamaModelsDir string

	// DevCachePaths maps tool name to its cache directory
	DevCachePaths map[string]string

	// XcodeDerivedData is the Xcode DerivedData path
	XcodeDerivedData string

	// XcodeArchives is the Xcode Archives path
	XcodeArchives string

	// XcodeSimulators is the CoreSimulator Devices path
	XcodeSimulators string

	// DockerRawPath is the Docker Desktop virtual disk image
	DockerRawPath string

	// TrashDir is the user's Trash directory
	TrashDir string

	// BlacklistedPaths are app bundle IDs that must never be deleted
	BlacklistedPaths map[string]bool

	// BlacklistedPrefixes are path prefixes under which nothing is deleted
	BlacklistedPrefixes []string
)

Functions

func Bold

func Bold(msg string, args ...any)

Bold prints bold text

func Colorize added in v1.2.0

func Colorize(code, s string) string

Colorize wraps s in the given ANSI code and a reset.

func Error

func Error(msg string, args ...any)

Error prints an error message

func FormatBytes

func FormatBytes(b int64) string

FormatBytes returns a human-readable byte string (e.g. "1.5 GB")

func Info

func Info(msg string, args ...any)

Info prints an informational message

func ProgressBar added in v1.2.0

func ProgressBar(pct, width int) string

ProgressBar renders a fixed-width unicode bar for a 0..100 percentage, colored green/yellow/red by fill level. width is the number of cells.

func RiskColor

func RiskColor(r RiskLevel) string

RiskColor returns the ANSI color for a risk level

func SeverityColor

func SeverityColor(s Severity) string

SeverityColor returns the ANSI color for a severity level

func Success

func Success(msg string, args ...any)

Success prints a success message

func Warn

func Warn(msg string, args ...any)

Warn prints a warning message

Types

type AnalysisResult

type AnalysisResult struct {
	Domain    string          `json:"domain"`
	Severity  Severity        `json:"severity"`
	TotalSize int64           `json:"total_size_bytes"`
	Items     []CleanableItem `json:"items"`
	Summary   string          `json:"summary"`
	Timestamp time.Time       `json:"timestamp"`
	Error     string          `json:"error,omitempty"`
}

AnalysisResult holds the result of analyzing one domain

func RunAnalyzers

func RunAnalyzers(tasks []RunnerTask, timeoutSecs int) []AnalysisResult

RunAnalyzers executes all analyzer tasks in parallel with a timeout. Returns results for all domains, including error results for timeouts/failures.

type AnalyzeFunc

type AnalyzeFunc func() (AnalysisResult, error)

AnalyzeFunc is the signature for any analyzer's Analyze method

type ApprovalEngine

type ApprovalEngine struct {
	Mode    ApprovalMode
	DryRun  bool
	Execute bool
	// contains filtered or unexported fields
}

ApprovalEngine handles user approval for cleanup operations

func NewApprovalEngine

func NewApprovalEngine(mode ApprovalMode, dryRun, execute bool) *ApprovalEngine

NewApprovalEngine creates a new approval engine

func (*ApprovalEngine) FilterItems

func (a *ApprovalEngine) FilterItems(results []AnalysisResult) []CleanableItem

FilterItems applies the approval mode to filter items the user wants to delete. Returns only the approved items.

type ApprovalMode

type ApprovalMode string

ApprovalMode defines how the user approves deletions

const (
	ApprovalDeal      ApprovalMode = "deal"
	ApprovalCategory  ApprovalMode = "category"
	ApprovalItem      ApprovalMode = "item"
	ApprovalChecklist ApprovalMode = "checklist"
)

type CleanableItem

type CleanableItem struct {
	Path         string    `json:"path"`
	SizeBytes    int64     `json:"size_bytes"`
	Label        string    `json:"label"`
	Domain       string    `json:"domain"`
	SafeToDelete bool      `json:"safe_to_delete"`
	Reason       string    `json:"reason"`
	AgeDays      int       `json:"age_days,omitempty"`
	Risk         RiskLevel `json:"risk"`
}

CleanableItem represents a single file or directory that can be cleaned

type DeleteResult

type DeleteResult struct {
	Path      string `json:"path"`
	Result    string `json:"result"` // success, skipped-blacklisted, skipped-dry-run, skipped-not-found, failure
	SizeBytes int64  `json:"size_bytes,omitempty"`
	Error     string `json:"error,omitempty"`
}

DeleteResult records what happened when deleting an item

type DiskSnapshot added in v1.2.0

type DiskSnapshot struct {
	TotalBytes int64
	UsedBytes  int64
	AvailBytes int64
	PctUsed    int
	OK         bool
}

DiskSnapshot is a lightweight view of the data volume usage, used by the banner and any caller that needs a quick free-space reading without running a full analysis.

func ReadDiskSnapshot added in v1.2.0

func ReadDiskSnapshot() DiskSnapshot

ReadDiskSnapshot returns current usage of the macOS data volume via `df`. On any parse/exec error it returns a snapshot with OK=false so callers can degrade gracefully instead of failing.

type RiskLevel

type RiskLevel string

RiskLevel represents the risk of deleting an item

const (
	RiskSafe   RiskLevel = "safe"
	RiskWarn   RiskLevel = "warn"
	RiskDanger RiskLevel = "danger"
)

type RunnerTask

type RunnerTask struct {
	Domain    string
	AnalyzeFn AnalyzeFunc
}

RunnerTask pairs a domain name with its analyze function

type Severity

type Severity string

Severity represents analysis severity based on size

const (
	SeverityCritical Severity = "critical"
	SeverityHigh     Severity = "high"
	SeverityMedium   Severity = "medium"
	SeverityLow      Severity = "low"
)

func SeverityFromSize

func SeverityFromSize(bytes int64) Severity

SeverityFromSize returns severity based on total bytes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL