scan

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package scan finds projects under the root and reads their state: stack, git, running processes, disk use and activity. It only reads; it never changes anything on disk except its own size cache.

Index

Constants

This section is empty.

Variables

View Source
var BuildDirs = []string{"node_modules", "target", ".next", "dist", "build", ".turbo", "src-tauri/target"}

BuildDirs are the only folders cleanup may remove (Safety rule 2). Sizes report them separately so the dashboard shows what is reclaimable.

Functions

func DirSize

func DirSize(dir string) int64

DirSize is the allocated size of a folder, symlinks not followed.

func PackageScripts

func PackageScripts(abs string) map[string]string

PackageScripts returns the scripts in a folder's package.json, or nil.

Types

type Detail

type Detail struct {
	Changes []string // `git status --short` lines
	Commits []string // recent commits, one line each
	Readme  []string // first non-empty README lines
	Scripts []string // package.json scripts as "name: command"
}

Detail is what the project detail view shows beyond the dashboard row.

func LoadDetail

func LoadDetail(ctx context.Context, p Project) Detail

type GitState

type GitState struct {
	Branch     string
	Upstream   string
	Ahead      int
	Behind     int
	Dirty      int
	Untracked  int
	LastCommit time.Time
	Subject    string
	Remote     string
	Host       string
	Owner      string
	Cloning    bool
	NoCommits  bool
	Err        string
}

type Kind

type Kind int
const (
	KindRepo  Kind = iota // a git repo
	KindGroup             // a folder that only holds repos, e.g. acme
	KindPlain             // a top-level folder with no git anywhere inside
)

type Listener

type Listener struct {
	PID     int
	Command string
	Port    int
	Cwd     string
}

type Project

type Project struct {
	Rel      string // path relative to root, e.g. "acme/web"
	Abs      string
	Name     string
	Depth    int // 1 for top-level folders
	Kind     Kind
	Archived bool // inside the archive folder

	Stack        []string
	Docker       bool
	NotInstalled bool // package.json but no node_modules
	Port         int  // expected dev port, 0 if unknown
	PortSource   string

	Git        GitState
	LastChange time.Time
	Activity   string // active | warm | dormant | abandoned | ""

	Running    []Listener
	Containers []string

	Size *Sizes // nil until measured
}

func Discover

func Discover(root, archive string, depth int, ignore func(rel string) bool) []Project

Discover lists every git repo up to depth levels under root, the folders that only hold repos (groups), and top-level folders with no git at all. The result is in tree order: each group or repo precedes what it contains.

The archive folder is a group whenever it holds anything, its direct children count as top-level (so an archived folder without git still shows and can be restored), and it gets one extra level of depth because archived projects keep their path, e.g. archive/acme/web.

func (*Project) IsRunning

func (p *Project) IsRunning() bool

IsRunning reports whether any listener or container belongs to the project.

func (*Project) StackLabel

func (p *Project) StackLabel() string

StackLabel is the primary stack plus any secondary ones, e.g. "Tauri".

func (*Project) Unpushed

func (p *Project) Unpushed() bool

Unpushed reports commits ahead of the upstream, or a branch with no upstream.

type Scanner

type Scanner struct {
	Sizes *SizeCache
	// contains filtered or unexported fields
}

func NewScanner

func NewScanner(cfg *config.Config, debug *log.Logger, stateDir string) *Scanner

func (*Scanner) Fast

func (s *Scanner) Fast(ctx context.Context) []Project

Fast finds projects and reads everything except folder sizes, which come from the cache. It runs git in up to 8 projects at once.

func (*Scanner) MeasureAll

func (s *Scanner) MeasureAll(ctx context.Context, ps []Project, force bool, done func(abs string, sz Sizes))

MeasureAll measures folder sizes in the background, 3 at a time, calling done for each project as it finishes. With force, cached sizes are ignored.

type SizeCache

type SizeCache struct {
	// contains filtered or unexported fields
}

SizeCache keeps measured sizes on disk between runs.

func OpenSizeCache

func OpenSizeCache(stateDir string) *SizeCache

func (*SizeCache) Fresh

func (c *SizeCache) Fresh(abs string) bool

func (*SizeCache) Get

func (c *SizeCache) Get(abs string) (Sizes, bool)

func (*SizeCache) Put

func (c *SizeCache) Put(abs string, s Sizes)

func (*SizeCache) Save

func (c *SizeCache) Save() error

type Sizes

type Sizes struct {
	Total     int64            `json:"total"`
	Build     int64            `json:"build"`
	BuildDirs map[string]int64 `json:"build_dirs"`
	ScannedAt time.Time        `json:"scanned_at"`
}

func Measure

func Measure(abs string) Sizes

Measure walks a project and returns its disk use. Nested repos are skipped, since they are projects of their own. Symlinks are not followed.

Jump to

Keyboard shortcuts

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