Skip to main content

Module clean

Module clean 

Source
Expand description

Worktree cleanup for finished runs: blyte clean, on review, and at dispatch.

Structs§

CleanContext
Context for cleaning a repository, caching metadata to avoid redundant git calls and disk reads.
CleanRepoStats
GitWorktreeInfo
RefEntry

Enums§

KeptReason
RemovalReason

Constants§

DEFAULT_SESSION_IDLE_DAYS
Default idle threshold in days for session worktrees.

Functions§

check_session_worktree_removable_with_ctx
clean_on_review
Removes a run’s worktree on review after recording the verdict under the same rules. Removes the worktree only when the rules allow it now (e.g. redone, or work already merged); otherwise prints nothing extra beyond the verdict line, except for accepted/fixed prints worktree .wt/<id> kept until wip/<id> is merged.
clean_repo
Cleans one repository.
clean_repo_with_options
Cleans one repository with configurable session worktree idle threshold and process cwd list.
clean_surfaces
Returns one line per thing removed (or, with dry_run, that would be removed).
dir_size
Recursively computes directory size in bytes without following symlinks.
display_worktree_path
Formats a worktree path for display and for git CLI commands: relative to root if inside root or a sibling (same parent directory); otherwise absolute.
find_blyte_worktrees
Lists all .wt/<id> directories that have a corresponding .wt/<id>.start.json.
find_default_branch
Identifies the default branch (origin/HEAD’s target, else main, else master).
find_repo_root
Finds the root repository (resolving the main checkout if inside a linked worktree).
format_size
Formats byte count into human-readable representation: e.g. “812 MB”, “12.3 GB”.
get_branch_tip
Returns the commit SHA at the tip of branch_name if it exists.
has_dispatched_runs
Returns true if <wt_path>/.wt/ contains any *.start.json file.
has_uncommitted_changes
Checks whether a worktree has uncommitted changes via git status --porcelain.
has_wt_component
Returns true if any path component is .wt.
is_branch_merged
Checks whether a branch’s work is on the default branch when any of:
is_linked_worktree
Returns true if root is a linked worktree (its git-dir differs from its git-common-dir).
is_pid_alive
Checks whether a process with the given PID is alive.
is_research
Checks whether a run is a research run from its start file.
is_session_worktree
Returns true if wt_path is a session worktree of root:
is_worktree_clean
Checks whether a worktree’s working tree is clean: git status --porcelain lists nothing other than .DS_Store files, at any depth.
is_worktree_idle
Returns whether index and HEAD in the worktree’s git admin directory (git -C <wt> rev-parse --absolute-git-dir) are both more than idle_days days old. Errors name what could not be read.
is_worktree_in_use
Returns true if any process working directory in cwds is wt_path or a subdirectory of it. Compares canonical paths.
list_running_process_cwds
Lists the current working directories of all running processes via lsof -a -d cwd -Fn.
parse_lsof_cwd_output
Parses lsof -a -d cwd -Fn output into a list of working directory paths.
parse_worktree_list
Parses git worktrees from git worktree list --porcelain.
read_start_record
Reads .wt/<id>.start.json from disk now.
remove_finished_run
Removes a finished run <id> when its work is merged (or it made no changes) and its worktree has no uncommitted changes.
run
Runs the blyte clean command.
spawn_background_clean
Starts blyte clean --quiet [--skip <ID>] in the background without waiting for it.