clean-sweep-tui 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- clean_sweep_tui-0.1.0/.gitignore +102 -0
- clean_sweep_tui-0.1.0/.python-version +1 -0
- clean_sweep_tui-0.1.0/CLAUDE.md +71 -0
- clean_sweep_tui-0.1.0/LICENSE +674 -0
- clean_sweep_tui-0.1.0/PKG-INFO +163 -0
- clean_sweep_tui-0.1.0/README.md +142 -0
- clean_sweep_tui-0.1.0/clean_sweep/__init__.py +3 -0
- clean_sweep_tui-0.1.0/clean_sweep/cleaners/__init__.py +0 -0
- clean_sweep_tui-0.1.0/clean_sweep/cleaners/_common.py +19 -0
- clean_sweep_tui-0.1.0/clean_sweep/cleaners/apps.py +31 -0
- clean_sweep_tui-0.1.0/clean_sweep/cleaners/custom.py +70 -0
- clean_sweep_tui-0.1.0/clean_sweep/cleaners/dev.py +144 -0
- clean_sweep_tui-0.1.0/clean_sweep/cleaners/logs.py +33 -0
- clean_sweep_tui-0.1.0/clean_sweep/cleaners/registry.py +30 -0
- clean_sweep_tui-0.1.0/clean_sweep/cleaners/spec.py +41 -0
- clean_sweep_tui-0.1.0/clean_sweep/cleaners/system.py +163 -0
- clean_sweep_tui-0.1.0/clean_sweep/cleaners/user.py +101 -0
- clean_sweep_tui-0.1.0/clean_sweep/cli.py +26 -0
- clean_sweep_tui-0.1.0/clean_sweep/tui.py +279 -0
- clean_sweep_tui-0.1.0/main.py +8 -0
- clean_sweep_tui-0.1.0/memory/MEMORY.md +3 -0
- clean_sweep_tui-0.1.0/memory/no-claude-commit-attribution.md +12 -0
- clean_sweep_tui-0.1.0/pyproject.toml +35 -0
- clean_sweep_tui-0.1.0/showcase.png +0 -0
- clean_sweep_tui-0.1.0/uv.lock +134 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# ---- Python ----
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
|
|
7
|
+
# Distribution / packaging
|
|
8
|
+
.Python
|
|
9
|
+
build/
|
|
10
|
+
develop-eggs/
|
|
11
|
+
dist/
|
|
12
|
+
downloads/
|
|
13
|
+
eggs/
|
|
14
|
+
.eggs/
|
|
15
|
+
lib/
|
|
16
|
+
lib64/
|
|
17
|
+
parts/
|
|
18
|
+
sdist/
|
|
19
|
+
var/
|
|
20
|
+
wheels/
|
|
21
|
+
share/python-wheels/
|
|
22
|
+
*.egg-info/
|
|
23
|
+
.installed.cfg
|
|
24
|
+
*.egg
|
|
25
|
+
MANIFEST
|
|
26
|
+
|
|
27
|
+
# PyInstaller
|
|
28
|
+
*.manifest
|
|
29
|
+
*.spec
|
|
30
|
+
|
|
31
|
+
# Installer logs
|
|
32
|
+
pip-log.txt
|
|
33
|
+
pip-delete-this-directory.txt
|
|
34
|
+
|
|
35
|
+
# Unit test / coverage
|
|
36
|
+
htmlcov/
|
|
37
|
+
.tox/
|
|
38
|
+
.nox/
|
|
39
|
+
.coverage
|
|
40
|
+
.coverage.*
|
|
41
|
+
.cache
|
|
42
|
+
nosetests.xml
|
|
43
|
+
coverage.xml
|
|
44
|
+
*.cover
|
|
45
|
+
*.py,cover
|
|
46
|
+
.hypothesis/
|
|
47
|
+
.pytest_cache/
|
|
48
|
+
cover/
|
|
49
|
+
|
|
50
|
+
# Type checkers / linters
|
|
51
|
+
.mypy_cache/
|
|
52
|
+
.dmypy.json
|
|
53
|
+
dmypy.json
|
|
54
|
+
.pyre/
|
|
55
|
+
.pytype/
|
|
56
|
+
.ruff_cache/
|
|
57
|
+
|
|
58
|
+
# Environments
|
|
59
|
+
.env
|
|
60
|
+
.env.*
|
|
61
|
+
!.env.example
|
|
62
|
+
.venv/
|
|
63
|
+
venv/
|
|
64
|
+
ENV/
|
|
65
|
+
env/
|
|
66
|
+
env.bak/
|
|
67
|
+
venv.bak/
|
|
68
|
+
|
|
69
|
+
# uv
|
|
70
|
+
# Lock file is checked in; ignore local caches if any
|
|
71
|
+
.uv-cache/
|
|
72
|
+
|
|
73
|
+
# Jupyter
|
|
74
|
+
.ipynb_checkpoints
|
|
75
|
+
profile_default/
|
|
76
|
+
ipython_config.py
|
|
77
|
+
|
|
78
|
+
# ---- IDE / Editors ----
|
|
79
|
+
.vscode/
|
|
80
|
+
.idea/
|
|
81
|
+
*.swp
|
|
82
|
+
*.swo
|
|
83
|
+
*~
|
|
84
|
+
|
|
85
|
+
# ---- OS ----
|
|
86
|
+
.DS_Store
|
|
87
|
+
.DS_Store?
|
|
88
|
+
._*
|
|
89
|
+
.Spotlight-V100
|
|
90
|
+
.Trashes
|
|
91
|
+
ehthumbs.db
|
|
92
|
+
Thumbs.db
|
|
93
|
+
desktop.ini
|
|
94
|
+
|
|
95
|
+
# ---- Logs / temp ----
|
|
96
|
+
*.log
|
|
97
|
+
logs/
|
|
98
|
+
tmp/
|
|
99
|
+
.tmp/
|
|
100
|
+
|
|
101
|
+
# ---- CleanSweep 自定义清理列表(本地用,含私人路径) ----
|
|
102
|
+
custom.json
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.14
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project
|
|
6
|
+
|
|
7
|
+
`CleanSweep` 是一个一键清空各类开发缓存(以及部分用户目录、应用配置)的命令行工具,仅面向 Linux。Python ≥3.10(开发用 3.14),uv 管理依赖。第三方库:`rich`(执行阶段的终端输出)+ `textual`(勾选清理项的 TUI)。
|
|
8
|
+
|
|
9
|
+
代码在 `clean_sweep/` 包内。入口是 `clean_sweep/cli.py` 的 `main()`:拉起 TUI 让用户一次性勾选要清理的项,TUI 退出后回到普通终端按顺序执行被选中项。`main()` 也是 pyproject `[project.scripts]` 注册的 `clean-sweep` 命令入口;仓库根目录的 `main.py` 只是 `from clean_sweep.cli import main; main()` 的薄壳,让 `uv run main.py` 仍等价于装好后的 `clean-sweep`。
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
- 运行:`uv run main.py`(或装好后 `clean-sweep`)
|
|
14
|
+
- 同步依赖:`uv sync`
|
|
15
|
+
- 新增依赖:`uv add <pkg>`
|
|
16
|
+
- 构建发布产物:`uv build`(生成 `dist/*.whl` 与 `*.tar.gz`);上传 `uv publish`
|
|
17
|
+
|
|
18
|
+
没有测试套件,没有 linter 配置。VSCode 会跑 Ruff 类型的诊断(PostToolUse 会回传 `ide_diagnostics`),别忽略警告。
|
|
19
|
+
|
|
20
|
+
## Architecture
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
main.py # 根目录薄壳:import clean_sweep.cli.main 并调用
|
|
24
|
+
clean_sweep/
|
|
25
|
+
├── cli.py # 入口 main():跑 TUI 拿到选中的 key,退出后按顺序 run() 每条命令
|
|
26
|
+
├── tui.py # textual TUI:勾选列表 + 实时预览 + 一次性确认弹窗
|
|
27
|
+
└── cleaners/
|
|
28
|
+
├── _common.py # 共享 console / run / has
|
|
29
|
+
├── spec.py # Category 枚举 + Step 数据类(清理项的统一描述模型)
|
|
30
|
+
├── registry.py # 汇总各模块 steps(),按 ORDER 固定顺序返回
|
|
31
|
+
├── dev.py # 开发工具缓存:docker, pnpm, npm, bun, go, rust, sdkman, gradle, maven
|
|
32
|
+
├── system.py # 系统级:dnf, apt, journal, ~/.cache, /var/cache, 缩略图, 崩溃报告, snap, flatpak
|
|
33
|
+
├── user.py # 用户数据目录:Documents/.../Videos + 回收站(含外部盘 .Trash-<uid>)
|
|
34
|
+
├── logs.py # 家目录下所有 .log 日志文件
|
|
35
|
+
├── apps.py # 应用配置:Claude (.claude 文件夹 + .claude.json)
|
|
36
|
+
└── custom.py # 自定义:读 ~/.config/clean-sweep/custom.json 的 paths 列表
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
数据流:`registry.all_steps()` 收齐所有 `Step` → `tui.CleanSweepApp` 渲染勾选列表(右侧预览 `Step.cmds`)→ 用户勾选 + 回车 → 一次性确认弹窗 → `app.run()` 返回选中的 key 列表 → `cli.main()` 对每个选中 `Step` 的 `cmds` 逐条 `run(...)`。
|
|
40
|
+
|
|
41
|
+
包内模块一律用相对导入(`from .cleaners.registry import ...`、`from .spec import ...`)。
|
|
42
|
+
|
|
43
|
+
**交互不再是逐项二次确认**:上下/jk 移动,空格勾选,`a` 全选 / `n` 全不选 / `c` 仅缓存,回车执行;确认弹窗是唯一一道闸门(回车确认,esc 取消)。
|
|
44
|
+
|
|
45
|
+
模块按 **删除对象的性质** 分组(`Step.category`),不是按工具分组。这个 `category` 同时决定 TUI 行为,是项目最重要的安全约定:
|
|
46
|
+
- `Category.CACHE`(`dev.py` 全部 + `system.py` 的 `~/.cache`):只动缓存,最坏是下次构建变慢——**默认勾选**,无危险标记。
|
|
47
|
+
- `Category.USER_DATA / SYSTEM / CONFIG / CUSTOM`(即 `spec.DESTRUCTIVE`):删用户数据、配置、系统状态或需 `sudo`——**默认不勾选**,列表里带 `!` 危险标记,确认弹窗里单独统计。新增同类清理时务必归到正确 category,别错标成 CACHE。
|
|
48
|
+
|
|
49
|
+
### 命令规格
|
|
50
|
+
|
|
51
|
+
每个 cleaner 模块里,要执行的 shell 命令抽成模块级的 `_<thing>_cmds() -> list[str]`(**不带 `sudo` 前缀**),与 `steps()` 分开维护。模块的 `steps()` 把命令包装成 `Step`:需要提权的在 `steps()` 里给每条命令拼上 `sudo ` 并设 `needs_sudo=True`,`Step.cmds` 即最终命令、也直接当预览展示(所见即所执行)。
|
|
52
|
+
|
|
53
|
+
`var_cache` / `user_dirs` / `claude` / `custom` 这类目标随系统状态变化的,命令按当前真实存在的路径动态生成,对应模块导出 `*_existing()` 辅助函数给 `steps()` 用(同时决定 `available`)。
|
|
54
|
+
|
|
55
|
+
### 共用约定(来自 `_common.py`)
|
|
56
|
+
|
|
57
|
+
- `run(cmd)`:所有 shell 操作都走它——它会先 `console.print` 出命令本身(青色),再 `subprocess.run(..., check=False)`。**不要绕开它直接调 `subprocess` / `os.system`**,否则用户看不到执行的是什么。执行只在 TUI 退出后的 `cli.main()` 里发生。
|
|
58
|
+
- `has(name)`:检测可执行文件是否存在,用于 `steps()` 里算 `available`。工具/路径不存在的项在 TUI 里置灰、不可勾选,不报错退出;整体必须能跨环境跑通。
|
|
59
|
+
- 路径里有用户输入或可能含特殊字符时用 `shlex.quote`(参考 `user.py` / `apps.py`)。`dev.py` 里硬编码的工具命令可以不用。
|
|
60
|
+
|
|
61
|
+
### 增加一个新的 cleaner
|
|
62
|
+
|
|
63
|
+
1. 判断它属于哪类(开发缓存 / 系统级 / 用户数据 / 应用配置 / 自定义),写到对应文件里;性质不同就新开一个模块(记得在 `registry.py` import 它)。
|
|
64
|
+
2. 把命令抽成模块级 `_<thing>_cmds() -> list[str]`(不带 `sudo`)。目标随系统状态变化的,再导出一个 `*_existing()` 给 `steps()` 用。
|
|
65
|
+
3. 在该模块的 `steps()` 里追加一条 `Step(key, name, category, cmds, available=..., reason=..., note=..., needs_sudo=...)`:`category` 决定默认勾选与危险标记,缺工具/路径时 `available=False` 并给 `reason`;需提权则 `cmds` 里每条拼 `sudo ` 且 `needs_sudo=True`。
|
|
66
|
+
4. 把新 `key` 加进 `registry.ORDER`,位置就是 TUI 里的显示/执行顺序。
|
|
67
|
+
5. 不要再写 `clean_*()`,也不要在函数里 `Confirm.ask` —— 确认统一由 TUI 的弹窗负责。
|
|
68
|
+
|
|
69
|
+
## 文档同步
|
|
70
|
+
|
|
71
|
+
每次实现新功能或修改既有功能后,**必须查看 `README.md` 是否需要同步更新**(清理项列表、使用说明、架构描述等)。需要更新就直接改,不要等用户提醒。
|