This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Weave Node Manager (wnm) is a Python application for managing Autonomi nodes on Linux and macOS systems. The system automatically manages node lifecycle: creating, starting, stopping, upgrading, and removing nodes based on system resource thresholds (CPU, memory, disk, network I/O, load average).
Platforms:
- Linux: systemd or setsid for process management, UFW for firewall (root or user-level)
- macOS: launchd for process management, no firewall management (user-level only)
- Python 3.12.3+ required
./scripts/test-macos.sh
# or
pytest tests/ -v -m "not linux_only"
python3 -m wnm --dry_run- Data:
~/Library/Application Support/autonomi/ - Logs:
~/Library/Logs/autonomi/ - Nodes:
~/Library/LaunchAgents/ - Some tests marked
@pytest.mark.linux_onlywill be skipped
./scripts/test.sh # run tests
./scripts/dev.sh # interactive shell# Setup
python3 -m venv .venv && . .venv/bin/activate
pip3 install -r requirements.txt -r requirements-dev.txt
# Format
black src/ && isort src/
# Build
python3 -m build
twine upload dist/*Single-execution cycle, invoked via cron each minute:
- Locking: Platform-specific lock file prevents concurrent runs
- Configuration: Loads machine config from SQLite (
colony.db) - Metrics Collection: CPU, memory, disk, I/O, load average + node statuses
- Decision Engine: Plans actions based on thresholds and concurrency limits
- Action Execution: Performs operations via ProcessManager
- Cleanup: Removes lock file and exits
models.py: SQLAlchemy ORM —Machine(single row, cluster config) andNode(one row per node)config.py: Multi-layer config — CLI args → env vars → config files → DB → defaults; globaloptions,machine_config, session factoryScreated at importdecision_engine.py:DecisionEngineclass;_compute_features()+plan_actions()executor.py:ActionExecutorclass; executes planned actions and all--force_actionvariantsutils.py: Metrics polling (read_node_metrics(),read_node_metadata()), counter/state updatesprocess_managers/: Factory pattern —SystemdManager,LaunchdManager,SetsidManager,AntctlManager,AntctlZenManager,DockerManagerall implementProcessManagerbasefirewall/:UfwManager(Linux) andNullFirewallManager(macOS/fallback)
RUNNING → STOPPED → RESTARTING → UPGRADING → REMOVING → deleted; DEAD (missing dir, immediate removal); DISABLED (excluded from management)
- Reboot detection → resurvey all nodes
- Dead node cleanup (immediate)
- Version field updates
- Delay expiration for transitional states
- Resource pressure removal (CPU/Mem/HD/IO/Load)
- Upgrades (only when
--enable_upgradepassed; blocked during removals) - Node addition (stopped nodes first, then create new)
- Idle survey
- Node ports:
port_start * 1000 + node_id(default: 55000+) - Metrics ports:
metrics_port_start * 1000 + node_id(default: 13000+) - Cannot be changed after
--init
Per-type limits (--max_concurrent_upgrades/starts/removals, default 1) combined with a global cap (--max_concurrent_operations, default 1). Effective limit = MIN(per-type, remaining global). See docs/USER-GUIDE-PART3.md for configuration examples.
- Single
Machinerow (id=1); all config updates apply cluster-wide - Nodes selected for removal by "youngest" (
agetimestamp) - Upgrades skipped unless
--enable_upgradeis passed (antnode self-upgrades by default) - Linux root mode requires sudo for systemd and UFW
--port_start,--metrics_port_start, and--process_managerare immutable after--init