Prompt file imported from JaniDhruv/slothd (
.github/prompts/new-sorter.prompt.md). Copyright stays with the author.
Add a New Organization Rule to slothd
You are helping a developer add a new file category, destination directory structure, or custom sorting rule to slothd.
Context & Architecture
In slothd, file moves are calculated in slothd/engine/organizer.py via compute_destination(scanned_file, base_dir).
Requirements
- Date-Hierarchy: Default structure is
{base_dir}/{Category}/{YYYY}/{MonthName}/{Filename}. - AI Classification Priority: If
scanned_file.ai_categoryis populated by Gemma 3, it must take precedence overscanned_file.basic_category. - Clean Filename Generation: If
scanned_file.ai_proposed_nameis present, rename the file using{ai_proposed_name}{extension}. - Collision Safety: Always pass the computed destination through
resolve_collision(dest_path)to append_1,_2instead of overwriting existing files. - Reversibility: Ensure the planned move works with
PlannedMoveso it is logged in SQLiteOperationLogforslothd undo.
Example Implementation Pattern
if scanned_file.ai_category == "MyCategory" or scanned_file.extension in (".myext",):
category_folder = base_dir / "MyCategory" / year_str / month_str
target_name = f"{scanned_file.ai_proposed_name}{scanned_file.extension}" if scanned_file.ai_proposed_name else scanned_file.name
return resolve_collision(category_folder / target_name)
Now, ask the user what category or file extensions they want to sort, and generate the corresponding code changes and unit test!
