macos-resource-optimizer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

macOS 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:
ScriptPurposeAgentsExecution Time
coordinator.py
40-agent parallel orchestrator40 agents (6 phases)4-5s
6 Phases (coordinator.py):
  1. Disk Cleanup (15 agents): Python/Node zombies, Browser helpers, Network leaks, Docker containers
  2. RAM Optimization (9 agents): Memory pressure, App profiler, Browser tabs, Electron apps
  3. Developer Cache (5 agents): Time Machine, Xcode, Build caches, Docker cleanup
  4. Advanced Memory (4 agents): Swap optimizer, WindowServer, Spotlight, Memory leaks
  5. Browser Deep Cleanup (3 agents): Chrome, Safari, Firefox optimizers
  6. 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数量执行时间
coordinator.py
40个Agent并行编排器40个Agent(6个阶段)4-5秒
6个执行阶段(coordinator.py):
  1. 磁盘清理(15个Agent):Python/Node僵尸进程、浏览器辅助进程、网络连接泄漏、Docker容器
  2. 内存优化(9个Agent):内存压力分析、应用性能剖析、浏览器标签页、Electron应用
  3. 开发缓存清理(5个Agent):Time Machine、Xcode、构建缓存、Docker清理
  4. 高级内存优化(4个Agent):交换分区优化、WindowServer、Spotlight、内存泄漏检测
  5. 浏览器深度清理(3个Agent):Chrome、Safari、Firefox优化器
  6. 应用与系统优化(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
undefined
bash
undefined

Execute 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
undefined
uv run scripts/coordinator.py --json
undefined

2. Individual Agents

2. 单独执行Agent

bash
undefined
bash
undefined

Memory 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
undefined
uv run scripts/agent_docker_deep_cleanup.py --dry-run
undefined

3. Utility Scripts

3. 实用脚本

bash
undefined
bash
undefined

Kill 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
undefined
uv run scripts/analyze_processes.py --json
undefined

MoAI Integration

MoAI 集成

Manager Agents

管理器Agent

manager-resource-coordinator.md:
python
undefined
manager-resource-coordinator.md:
python
undefined

Execute 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

返回汇总后的优化建议

undefined
undefined

Expert Agents

专家Agent

expert-memory-optimizer.md:
python
undefined
expert-memory-optimizer.md:
python
undefined

Execute 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

根据内存分析结果生成优化建议

undefined
undefined

Available Agents (40+)

可用Agent(40+个)

Phase 1: Disk Cleanup (15 agents)

阶段1:磁盘清理(15个Agent)

Process Cleanup:
  • agent_python_zombies.py
    - Python zombie processes
  • agent_node_process_scanner.py
    - Node/Bun zombie processes
  • agent_workerd_zombies.py
    - Cloudflare Workers zombies
  • agent_generic_idle.py
    - Generic idle process hunter
  • agent_jvm_memory_hog_detector.py
    - JVM memory hog detection
  • agent_ssh_git_process_zombies.py
    - SSH/Git process zombies
Application Helpers:
  • agent_browser_helpers.py
    - Chrome/Arc renderer helpers
  • agent_language_servers.py
    - VS Code language servers
  • agent_electron_helpers.py
    - Notion/Dia helpers
Network & Resources:
  • agent_network_connection_leaks.py
    - Network connection leaks
  • agent_orphaned_process_groups.py
    - Orphaned process groups
  • agent_docker_container_scanner.py
    - Docker container scanning
  • agent_database_connection_pooler.py
    - Database connection pooling
  • agent_ssh_connection_scanner.py
    - SSH connection scanning
  • agent_file_cache_optimizer.py
    - File cache optimization
进程清理:
  • agent_python_zombies.py
    - Python僵尸进程清理
  • agent_node_process_scanner.py
    - Node/Bun僵尸进程扫描
  • agent_workerd_zombies.py
    - Cloudflare Workers僵尸进程清理
  • agent_generic_idle.py
    - 通用闲置进程检测
  • agent_jvm_memory_hog_detector.py
    - JVM内存占用过高检测
  • agent_ssh_git_process_zombies.py
    - SSH/Git僵尸进程清理
应用辅助进程:
  • agent_browser_helpers.py
    - Chrome/Arc渲染辅助进程清理
  • agent_language_servers.py
    - VS Code语言服务进程管理
  • agent_electron_helpers.py
    - Notion/Dia等Electron应用辅助进程清理
网络与资源:
  • agent_network_connection_leaks.py
    - 网络连接泄漏检测
  • agent_orphaned_process_groups.py
    - 孤立进程组清理
  • agent_docker_container_scanner.py
    - Docker容器扫描
  • agent_database_connection_pooler.py
    - 数据库连接池优化
  • agent_ssh_connection_scanner.py
    - SSH连接扫描
  • agent_file_cache_optimizer.py
    - 文件缓存优化

Phase 2: RAM Optimization (9 agents)

阶段2:内存优化(9个Agent)

  • agent_memory_pressure_detector.py
    - Memory pressure analysis
  • agent_browser_tab_manager.py
    - Browser tab management
  • agent_browser_helper_consolidator.py
    - Browser helper consolidation
  • agent_browser_cache_optimizer.py
    - Browser cache optimization
  • agent_inactive_app_detector.py
    - Inactive application detection
  • agent_electron_app_optimizer.py
    - Electron app optimization
  • agent_background_app_suspender.py
    - Background app suspension
  • agent_swap_optimizer.py
    - Swap usage optimization
  • agent_memory_leak_hunter.py
    - Memory leak detection
  • 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
    - 闲置应用检测
  • agent_electron_app_optimizer.py
    - Electron应用优化
  • agent_background_app_suspender.py
    - 后台应用暂停
  • agent_swap_optimizer.py
    - 交换分区使用优化
  • agent_memory_leak_hunter.py
    - 内存泄漏检测

Phase 3: Developer Cache (5 agents)

阶段3:开发缓存清理(5个Agent)

  • agent_timemachine_snapshot_cleaner.py
    - Time Machine snapshots
  • agent_developer_cache_cleaner.py
    - Developer cache cleanup
  • agent_xcode_cache_cleaner.py
    - Xcode artifact cleanup
  • agent_build_cache_cleaner.py
    - Gradle/Maven cache cleanup
  • agent_system_log_cleaner.py
    - System log cleanup
  • agent_timemachine_snapshot_cleaner.py
    - Time Machine快照清理
  • agent_developer_cache_cleaner.py
    - 开发缓存清理
  • agent_xcode_cache_cleaner.py
    - Xcode产物清理
  • agent_build_cache_cleaner.py
    - Gradle/Maven构建缓存清理
  • agent_system_log_cleaner.py
    - 系统日志清理

Phase 4: Advanced Memory (4 agents)

阶段4:高级内存优化(4个Agent)

  • agent_swap_purgeable_hunter.py
    - Purgeable swap memory
  • agent_window_server_optimizer.py
    - WindowServer optimization
  • agent_spotlight_mds_hunter.py
    - Spotlight MDS optimization
  • agent_memory_leak_hunter.py
    - Memory leak detection
  • agent_swap_purgeable_hunter.py
    - 可释放交换内存检测
  • agent_window_server_optimizer.py
    - WindowServer优化
  • agent_spotlight_mds_hunter.py
    - Spotlight MDS优化
  • agent_memory_leak_hunter.py
    - 内存泄漏检测

Phase 5: Browser Deep Cleanup (3 agents)

阶段5:浏览器深度清理(3个Agent)

  • agent_chrome_deep_cleanup.py
    - Chrome deep cleanup
  • agent_safari_optimizer.py
    - Safari optimization
  • agent_firefox_deep_cleanup.py
    - Firefox cleanup
  • agent_chrome_deep_cleanup.py
    - Chrome深度清理
  • agent_safari_optimizer.py
    - Safari优化
  • agent_firefox_deep_cleanup.py
    - Firefox清理

Phase 6: App & System (3 agents)

阶段6:应用与系统优化(3个Agent)

  • agent_messaging_app_hunter.py
    - Messaging app optimization (Slack/Discord)
  • agent_vscode_deep_cleanup.py
    - VS Code cleanup
  • agent_dns_connection_scanner.py
    - DNS/Network optimization
  • agent_messaging_app_hunter.py
    - 即时通讯应用优化(Slack/Discord)
  • agent_vscode_deep_cleanup.py
    - VS Code清理
  • agent_dns_connection_scanner.py
    - DNS/网络优化

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()
```python

Manager 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

汇总结果并返回

undefined
undefined

Data Flow

数据流

python
undefined
python
undefined

coordinator.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 } }
undefined

Protected Apps

受保护应用

Default protected apps (from
config/cleanup-rules.json
):
  • Claude Code
  • Notion
  • Slack
  • Discord
  • Mail
  • 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
config/cleanup-rules.json
to add/remove protected apps based on your workflow.
These apps are NEVER killed or suspended during optimization.
默认受保护应用(来自
config/cleanup-rules.json
):
  • Claude Code
  • Notion
  • Slack
  • Discord
  • Mail
  • Messages
  • Ghostty
推荐额外保护的应用(针对开发环境):
  • Node.js(活跃开发进程)
  • Apple Virtualization(系统虚拟化进程)
  • VSCode/Cursor(开发编辑器)
  • Xcode(开发工具)
  • Docker Desktop(容器化工具)
自定义配置:编辑
config/cleanup-rules.json
,根据你的工作流添加或移除受保护应用。
这些应用在优化过程中绝不会被终止或暂停。

Performance Characteristics

性能指标

MetricValue
Total Agents40+ specialized agents
Orchestrators1 (coordinator only)
Execution Time (parallel)4-5s (first run), 2-3s (cached)
Execution Time (sequential)~40s (estimated)
Speed Improvement8× 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

工作流

  1. Delegate to manager-resource-coordinator
  2. Coordinator executes:
    uv run scripts/coordinator.py --json
  3. Parse JSON results
  4. Return formatted analysis with recommendations
undefined
  1. 委托给manager-resource-coordinator
  2. 编排器执行:
    uv run scripts/coordinator.py --json
  3. 解析JSON结果
  4. 返回格式化的分析报告与优化建议
undefined

/macos-resource-optimizer:2-optimize

/macos-resource-optimizer:2-optimize

markdown
Execute system optimization via coordinator.py.
markdown
通过coordinator.py执行系统优化。

Workflow

工作流

  1. Delegate to manager-resource-coordinator
  2. Coordinator executes:
    uv run scripts/coordinator.py --json
  3. Parse and validate results
  4. Apply optimizations if approved
  5. Return optimization results
undefined
  1. 委托给manager-resource-coordinator
  2. 编排器执行:
    uv run scripts/coordinator.py --json
  3. 解析并验证结果
  4. 若获得批准则应用优化措施
  5. 返回优化结果
undefined

Works Well With

兼容组件

MoAI Agents:
  • manager-resource-coordinator
    - Main orchestration (uses coordinator.py)
  • expert-memory-optimizer
    - Memory-specific agents
  • expert-cpu-optimizer
    - CPU optimization (future)
  • expert-disk-optimizer
    - Disk optimization agents
MoAI Skills:
  • moai-lang-python
    - Python 3.11+ async patterns
  • moai-foundation-core
    - TRUST 5 quality standards
  • moai-essentials-debug
    - Debugging subprocess issues
Commands:
  • /macos-resource-optimizer:0-init
    - Initialize configuration
  • /macos-resource-optimizer:1-analyze
    - Full system analysis
  • /macos-resource-optimizer:2-optimize
    - System optimization
  • /macos-resource-optimizer:3-monitor
    - Continuous monitoring
  • /macos-resource-optimizer:9-feedback
    - Submit 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
.claude/skills/macos-resource-optimizer/scripts/
Actual Performance: 4-5s first run, 2-3s cached (measured 2025-11-30)
MoAI Agent:
  • manager-resource-coordinator
    - 主编排器(基于coordinator.py)
  • expert-memory-optimizer
    - 内存专用Agent
  • expert-cpu-optimizer
    - CPU优化(规划中)
  • expert-disk-optimizer
    - 磁盘优化Agent
MoAI Skills:
  • moai-lang-python
    - Python 3.11+异步模式
  • moai-foundation-core
    - TRUST 5质量标准
  • 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)委托模式 实际脚本位置:
.claude/skills/macos-resource-optimizer/scripts/
实际性能: 首次运行4-5秒,缓存命中时2-3秒(2025-11-30测试数据)