macos-resource-optimizer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesemacOS Resource Optimizer
macOS资源优化工具
Production-ready system optimization with 40+ specialized agents for comprehensive macOS resource management.
可投入生产环境的系统优化工具,通过40+个专用Agent实现macOS资源的全面管理。
Quick Reference
快速参考
What is macOS Resource Optimizer?
Real-world macOS optimization framework with 40+ specialized agents executing in parallel:
- coordinator.py: 40-agent orchestrator (6 phases, 4-5s execution)
- 40+ specialized agents: Memory, disk, browser, Docker, developer tools
- Implementation: UV scripts (PEP 723) + Bash delegation via MoAI agents
Main Orchestrator:
| Script | Purpose | Agents | Execution Time |
|---|---|---|---|
| 40-agent parallel orchestrator | 40 agents (6 phases) | 4-5s |
6 Phases (coordinator.py):
- Disk Cleanup (15 agents): Python/Node zombies, Browser helpers, Network leaks, Docker containers
- RAM Optimization (9 agents): Memory pressure, App profiler, Browser tabs, Electron apps
- Developer Cache (5 agents): Time Machine, Xcode, Build caches, Docker cleanup
- Advanced Memory (4 agents): Swap optimizer, WindowServer, Spotlight, Memory leaks
- Browser Deep Cleanup (3 agents): Chrome, Safari, Firefox optimizers
- App & System (3 agents): Messaging apps, VSCode, DNS/Network
Performance:
- Sequential: 40 × 1.0s = 40s (estimated per agent)
- Parallel (6 phases): 4-5s total (8× faster than sequential)
- Real-world: 4-7s depending on system state and cache availability
- With MetricsCache (TTL 30s): ~2-3s on repeated calls
什么是macOS资源优化工具?
面向实际场景的macOS优化框架,40+个专用Agent并行执行:
- coordinator.py:40个Agent的编排器(6个阶段,执行时间4-5秒)
- 40+个专用Agent:覆盖内存、磁盘、浏览器、Docker、开发工具等场景
- 实现方式:UV脚本(PEP 723)+ 基于MoAI Agent的Bash委托执行
主编排器:
| 脚本 | 用途 | Agent数量 | 执行时间 |
|---|---|---|---|
| 40个Agent并行编排器 | 40个Agent(6个阶段) | 4-5秒 |
6个执行阶段(coordinator.py):
- 磁盘清理(15个Agent):Python/Node僵尸进程、浏览器辅助进程、网络连接泄漏、Docker容器
- 内存优化(9个Agent):内存压力分析、应用性能剖析、浏览器标签页、Electron应用
- 开发缓存清理(5个Agent):Time Machine、Xcode、构建缓存、Docker清理
- 高级内存优化(4个Agent):交换分区优化、WindowServer、Spotlight、内存泄漏检测
- 浏览器深度清理(3个Agent):Chrome、Safari、Firefox优化器
- 应用与系统优化(3个Agent):即时通讯应用、VSCode、DNS/网络
性能表现:
- 串行执行:40 × 1.0秒 = 40秒(单Agent预估执行时间)
- 并行执行(6个阶段):总耗时4-5秒(比串行快8倍)
- 实际场景:根据系统状态和缓存可用性,耗时4-7秒
- 启用MetricsCache(TTL 30秒):重复调用时耗时约2-3秒
Usage
使用方法
1. Full System Optimization (40 agents)
1. 全系统优化(40个Agent)
bash
undefinedbash
undefinedExecute all 40 agents in 6 parallel phases
分6个并行阶段执行全部40个Agent
uv run scripts/coordinator.py
uv run scripts/coordinator.py
JSON output
输出JSON格式结果
uv run scripts/coordinator.py --json
undefineduv run scripts/coordinator.py --json
undefined2. Individual Agents
2. 单独执行Agent
bash
undefinedbash
undefinedMemory pressure detector
内存压力检测器
uv run scripts/agent_memory_pressure_detector.py
uv run scripts/agent_memory_pressure_detector.py
Browser tab manager
浏览器标签页管理器
uv run scripts/agent_browser_tab_manager.py
uv run scripts/agent_browser_tab_manager.py
Docker cleanup
Docker清理(试运行模式)
uv run scripts/agent_docker_deep_cleanup.py --dry-run
undefineduv run scripts/agent_docker_deep_cleanup.py --dry-run
undefined3. Utility Scripts
3. 实用脚本
bash
undefinedbash
undefinedKill zombie processes
终止僵尸进程
uv run scripts/kill_zombies_parallel.py
uv run scripts/kill_zombies_parallel.py
Report memory usage
生成内存使用报告
uv run scripts/report_memory.py
uv run scripts/report_memory.py
Analyze running processes
分析运行中的进程(JSON输出)
uv run scripts/analyze_processes.py --json
undefineduv run scripts/analyze_processes.py --json
undefinedMoAI Integration
MoAI 集成
Manager Agents
管理器Agent
manager-resource-coordinator.md:
python
undefinedmanager-resource-coordinator.md:
python
undefinedExecute full 40-agent orchestration
执行完整的40个Agent编排流程
result = Bash("uv run .claude/skills/macos-resource-optimizer/scripts/coordinator.py --json")
data = json.loads(result.stdout)
result = Bash("uv run .claude/skills/macos-resource-optimizer/scripts/coordinator.py --json")
data = json.loads(result.stdout)
Parse results by phase
按阶段解析结果
phase1_results = data["phases"]["disk_cleanup"]
phase2_results = data["phases"]["ram_optimization"]
phase1_results = data["phases"]["disk_cleanup"]
phase2_results = data["phases"]["ram_optimization"]
Return aggregated recommendations
返回汇总后的优化建议
undefinedundefinedExpert Agents
专家Agent
expert-memory-optimizer.md:
python
undefinedexpert-memory-optimizer.md:
python
undefinedExecute memory-specific agents
执行内存相关的Agent
result = Bash("uv run scripts/agent_memory_pressure_detector.py --json")
memory_data = json.loads(result.stdout)
result = Bash("uv run scripts/agent_memory_pressure_detector.py --json")
memory_data = json.loads(result.stdout)
Generate recommendations based on memory analysis
根据内存分析结果生成优化建议
undefinedundefinedAvailable Agents (40+)
可用Agent(40+个)
Phase 1: Disk Cleanup (15 agents)
阶段1:磁盘清理(15个Agent)
Process Cleanup:
- - Python zombie processes
agent_python_zombies.py - - Node/Bun zombie processes
agent_node_process_scanner.py - - Cloudflare Workers zombies
agent_workerd_zombies.py - - Generic idle process hunter
agent_generic_idle.py - - JVM memory hog detection
agent_jvm_memory_hog_detector.py - - SSH/Git process zombies
agent_ssh_git_process_zombies.py
Application Helpers:
- - Chrome/Arc renderer helpers
agent_browser_helpers.py - - VS Code language servers
agent_language_servers.py - - Notion/Dia helpers
agent_electron_helpers.py
Network & Resources:
- - Network connection leaks
agent_network_connection_leaks.py - - Orphaned process groups
agent_orphaned_process_groups.py - - Docker container scanning
agent_docker_container_scanner.py - - Database connection pooling
agent_database_connection_pooler.py - - SSH connection scanning
agent_ssh_connection_scanner.py - - File cache optimization
agent_file_cache_optimizer.py
进程清理:
- - Python僵尸进程清理
agent_python_zombies.py - - Node/Bun僵尸进程扫描
agent_node_process_scanner.py - - Cloudflare Workers僵尸进程清理
agent_workerd_zombies.py - - 通用闲置进程检测
agent_generic_idle.py - - JVM内存占用过高检测
agent_jvm_memory_hog_detector.py - - SSH/Git僵尸进程清理
agent_ssh_git_process_zombies.py
应用辅助进程:
- - Chrome/Arc渲染辅助进程清理
agent_browser_helpers.py - - VS Code语言服务进程管理
agent_language_servers.py - - Notion/Dia等Electron应用辅助进程清理
agent_electron_helpers.py
网络与资源:
- - 网络连接泄漏检测
agent_network_connection_leaks.py - - 孤立进程组清理
agent_orphaned_process_groups.py - - Docker容器扫描
agent_docker_container_scanner.py - - 数据库连接池优化
agent_database_connection_pooler.py - - SSH连接扫描
agent_ssh_connection_scanner.py - - 文件缓存优化
agent_file_cache_optimizer.py
Phase 2: RAM Optimization (9 agents)
阶段2:内存优化(9个Agent)
- - Memory pressure analysis
agent_memory_pressure_detector.py - - Browser tab management
agent_browser_tab_manager.py - - Browser helper consolidation
agent_browser_helper_consolidator.py - - Browser cache optimization
agent_browser_cache_optimizer.py - - Inactive application detection
agent_inactive_app_detector.py - - Electron app optimization
agent_electron_app_optimizer.py - - Background app suspension
agent_background_app_suspender.py - - Swap usage optimization
agent_swap_optimizer.py - - Memory leak detection
agent_memory_leak_hunter.py
- - 内存压力分析
agent_memory_pressure_detector.py - - 浏览器标签页管理
agent_browser_tab_manager.py - - 浏览器辅助进程整合
agent_browser_helper_consolidator.py - - 浏览器缓存优化
agent_browser_cache_optimizer.py - - 闲置应用检测
agent_inactive_app_detector.py - - Electron应用优化
agent_electron_app_optimizer.py - - 后台应用暂停
agent_background_app_suspender.py - - 交换分区使用优化
agent_swap_optimizer.py - - 内存泄漏检测
agent_memory_leak_hunter.py
Phase 3: Developer Cache (5 agents)
阶段3:开发缓存清理(5个Agent)
- - Time Machine snapshots
agent_timemachine_snapshot_cleaner.py - - Developer cache cleanup
agent_developer_cache_cleaner.py - - Xcode artifact cleanup
agent_xcode_cache_cleaner.py - - Gradle/Maven cache cleanup
agent_build_cache_cleaner.py - - System log cleanup
agent_system_log_cleaner.py
- - Time Machine快照清理
agent_timemachine_snapshot_cleaner.py - - 开发缓存清理
agent_developer_cache_cleaner.py - - Xcode产物清理
agent_xcode_cache_cleaner.py - - Gradle/Maven构建缓存清理
agent_build_cache_cleaner.py - - 系统日志清理
agent_system_log_cleaner.py
Phase 4: Advanced Memory (4 agents)
阶段4:高级内存优化(4个Agent)
- - Purgeable swap memory
agent_swap_purgeable_hunter.py - - WindowServer optimization
agent_window_server_optimizer.py - - Spotlight MDS optimization
agent_spotlight_mds_hunter.py - - Memory leak detection
agent_memory_leak_hunter.py
- - 可释放交换内存检测
agent_swap_purgeable_hunter.py - - WindowServer优化
agent_window_server_optimizer.py - - Spotlight MDS优化
agent_spotlight_mds_hunter.py - - 内存泄漏检测
agent_memory_leak_hunter.py
Phase 5: Browser Deep Cleanup (3 agents)
阶段5:浏览器深度清理(3个Agent)
- - Chrome deep cleanup
agent_chrome_deep_cleanup.py - - Safari optimization
agent_safari_optimizer.py - - Firefox cleanup
agent_firefox_deep_cleanup.py
- - Chrome深度清理
agent_chrome_deep_cleanup.py - - Safari优化
agent_safari_optimizer.py - - Firefox清理
agent_firefox_deep_cleanup.py
Phase 6: App & System (3 agents)
阶段6:应用与系统优化(3个Agent)
- - Messaging app optimization (Slack/Discord)
agent_messaging_app_hunter.py - - VS Code cleanup
agent_vscode_deep_cleanup.py - - DNS/Network optimization
agent_dns_connection_scanner.py
- - 即时通讯应用优化(Slack/Discord)
agent_messaging_app_hunter.py - - VS Code清理
agent_vscode_deep_cleanup.py - - DNS/网络优化
agent_dns_connection_scanner.py
Architecture
架构
Execution Stack
执行栈
User Command (slash command)
↓
MoAI Command (Python orchestrator)
↓
Task() delegation to manager agents
↓
Manager-Resource-Coordinator (MoAI agent)
↓
Bash(uv run coordinator.py) → UV Script execution
↓
asyncio.gather() parallel execution
├─ Phase 1: Disk Cleanup (15 agents)
├─ Phase 2: RAM Optimization (9 agents)
├─ Phase 3: Developer Cache (5 agents)
├─ Phase 4: Advanced Memory (4 agents)
├─ Phase 5: Browser Cleanup (3 agents)
└─ Phase 6: App & System (3 agents)
↓
JSON results aggregation
↓
User-facing report (Korean)用户命令(斜杠命令)
↓
MoAI命令(Python编排器)
↓
委托任务给管理器Agent
↓
Manager-Resource-Coordinator(MoAI Agent)
↓
调用Bash工具执行:uv run coordinator.py → UV脚本执行
↓
通过asyncio.gather()实现并行执行
├─ 阶段1:磁盘清理(15个Agent)
├─ 阶段2:内存优化(9个Agent)
├─ 阶段3:开发缓存清理(5个Agent)
├─ 阶段4:高级内存优化(4个Agent)
├─ 阶段5:浏览器清理(3个Agent)
└─ 阶段6:应用与系统优化(3个Agent)
↓
JSON结果汇总
↓
面向用户的报告(韩语)Implementation Details
实现细节
Execution Method: UV Scripts (PEP 723)
bash
#!/usr/bin/env uv run执行方式:UV脚本(PEP 723)
bash
#!/usr/bin/env uv run/// script
/// script
requires-python = ">=3.11"
requires-python = ">=3.11"
dependencies = ["psutil", "pyyaml"]
dependencies = ["psutil", "pyyaml"]
///
///
import asyncio
import psutil
import asyncio
import psutil
Scripts run directly via: uv run script.py
脚本可直接通过以下命令运行:uv run script.py
No Python virtual environment setup required
无需配置Python虚拟环境
**Delegation Pattern**: Bash + Task()
```python
**委托模式**:Bash + Task()
```pythonManager agent receives command
管理器Agent接收命令
Delegates to Bash tool: uv run .claude/skills/.../scripts/coordinator.py
委托给Bash工具执行:uv run .claude/skills/.../scripts/coordinator.py
Coordinator spawns async tasks for 40 agents
编排器为40个Agent创建异步任务
Results aggregated and returned
汇总结果并返回
undefinedundefinedData Flow
数据流
python
undefinedpython
undefinedcoordinator.py executes agents
coordinator.py执行Agent后的返回结构
{
"phases": {
"disk_cleanup": {
"agents_executed": 15,
"duration": 2.1,
"savings_gb": 5.3,
"results": [...]
},
"ram_optimization": {
"agents_executed": 9,
"duration": 1.8,
"memory_freed_gb": 2.1,
"results": [...]
},
...
},
"summary": {
"total_agents": 40,
"total_duration": 2.5,
"total_savings_gb": 12.4,
"total_memory_freed_gb": 4.2
}
}
undefined{
"phases": {
"disk_cleanup": {
"agents_executed": 15,
"duration": 2.1,
"savings_gb": 5.3,
"results": [...]
},
"ram_optimization": {
"agents_executed": 9,
"duration": 1.8,
"memory_freed_gb": 2.1,
"results": [...]
},
...
},
"summary": {
"total_agents": 40,
"total_duration": 2.5,
"total_savings_gb": 12.4,
"total_memory_freed_gb": 4.2
}
}
undefinedProtected Apps
受保护应用
Default protected apps (from ):
config/cleanup-rules.json- Claude Code
- Notion
- Slack
- Discord
- Messages
- Ghostty
Recommended additional protection (for development environments):
- Node.js (active development processes)
- Apple Virtualization (system virtualization)
- VSCode/Cursor (development editors)
- Xcode (development tools)
- Docker Desktop (containerization)
Customization: Edit to add/remove protected apps based on your workflow.
config/cleanup-rules.jsonThese apps are NEVER killed or suspended during optimization.
默认受保护应用(来自):
config/cleanup-rules.json- Claude Code
- Notion
- Slack
- Discord
- Messages
- Ghostty
推荐额外保护的应用(针对开发环境):
- Node.js(活跃开发进程)
- Apple Virtualization(系统虚拟化进程)
- VSCode/Cursor(开发编辑器)
- Xcode(开发工具)
- Docker Desktop(容器化工具)
自定义配置:编辑,根据你的工作流添加或移除受保护应用。
config/cleanup-rules.json这些应用在优化过程中绝不会被终止或暂停。
Performance Characteristics
性能指标
| Metric | Value |
|---|---|
| Total Agents | 40+ specialized agents |
| Orchestrators | 1 (coordinator only) |
| Execution Time (parallel) | 4-5s (first run), 2-3s (cached) |
| Execution Time (sequential) | ~40s (estimated) |
| Speed Improvement | 8× faster (parallel vs sequential) |
| Memory Saved (typical) | 1-3 GB |
| Disk Saved (typical) | 0.4-2.5 GB |
| Actual Results (2025-11-30) | +413MB disk, 18% of goal |
| 指标 | 数值 |
|---|---|
| 总Agent数量 | 40+个专用Agent |
| 编排器数量 | 1个(仅coordinator) |
| 执行时间(并行) | 4-5秒(首次运行),2-3秒(缓存命中) |
| 执行时间(串行) | ~40秒(预估) |
| 速度提升 | 比串行快8倍 |
| 典型内存释放量 | 1-3 GB |
| 典型磁盘释放量 | 0.4-2.5 GB |
| 实际测试结果(2025-11-30) | 释放413MB磁盘空间,达到目标的18% |
Commands Integration
命令集成
/macos-resource-optimizer:1-analyze
/macos-resource-optimizer:1-analyze
markdown
Execute full system analysis via coordinator.py.markdown
通过coordinator.py执行全系统分析。Workflow
工作流
- Delegate to manager-resource-coordinator
- Coordinator executes:
uv run scripts/coordinator.py --json - Parse JSON results
- Return formatted analysis with recommendations
undefined- 委托给manager-resource-coordinator
- 编排器执行:
uv run scripts/coordinator.py --json - 解析JSON结果
- 返回格式化的分析报告与优化建议
undefined/macos-resource-optimizer:2-optimize
/macos-resource-optimizer:2-optimize
markdown
Execute system optimization via coordinator.py.markdown
通过coordinator.py执行系统优化。Workflow
工作流
- Delegate to manager-resource-coordinator
- Coordinator executes:
uv run scripts/coordinator.py --json - Parse and validate results
- Apply optimizations if approved
- Return optimization results
undefined- 委托给manager-resource-coordinator
- 编排器执行:
uv run scripts/coordinator.py --json - 解析并验证结果
- 若获得批准则应用优化措施
- 返回优化结果
undefinedWorks Well With
兼容组件
MoAI Agents:
- - Main orchestration (uses coordinator.py)
manager-resource-coordinator - - Memory-specific agents
expert-memory-optimizer - - CPU optimization (future)
expert-cpu-optimizer - - Disk optimization agents
expert-disk-optimizer
MoAI Skills:
- - Python 3.11+ async patterns
moai-lang-python - - TRUST 5 quality standards
moai-foundation-core - - Debugging subprocess issues
moai-essentials-debug
Commands:
- - Initialize configuration
/macos-resource-optimizer:0-init - - Full system analysis
/macos-resource-optimizer:1-analyze - - System optimization
/macos-resource-optimizer:2-optimize - - Continuous monitoring
/macos-resource-optimizer:3-monitor - - Submit feedback
/macos-resource-optimizer:9-feedback
Version: 2.1.0
Last Updated: 2025-11-30 (Phase 2.2 improvements)
Status: ✅ Production Ready (40+ agents, 1 orchestrator, UV scripts)
Architecture: Bash(uv run) delegation pattern via MoAI agents
Real Scripts: Located in
Actual Performance: 4-5s first run, 2-3s cached (measured 2025-11-30)
.claude/skills/macos-resource-optimizer/scripts/MoAI Agent:
- - 主编排器(基于coordinator.py)
manager-resource-coordinator - - 内存专用Agent
expert-memory-optimizer - - CPU优化(规划中)
expert-cpu-optimizer - - 磁盘优化Agent
expert-disk-optimizer
MoAI Skills:
- - Python 3.11+异步模式
moai-lang-python - - TRUST 5质量标准
moai-foundation-core - - 子进程问题调试
moai-essentials-debug
命令:
- - 初始化配置
/macos-resource-optimizer:0-init - - 全系统分析
/macos-resource-optimizer:1-analyze - - 系统优化
/macos-resource-optimizer:2-optimize - - 持续监控
/macos-resource-optimizer:3-monitor - - 提交反馈
/macos-resource-optimizer:9-feedback
版本: 2.1.0
最后更新: 2025-11-30(阶段2.2优化)
状态: ✅ 可投入生产环境(40+个Agent,1个编排器,UV脚本)
架构: 基于MoAI Agent的Bash(uv run)委托模式
实际脚本位置:
实际性能: 首次运行4-5秒,缓存命中时2-3秒(2025-11-30测试数据)
.claude/skills/macos-resource-optimizer/scripts/