villsim/.cursor/rules/01-config-management.mdc

55 lines
1.8 KiB
Plaintext

---
description: "Always use config.json as the single source of truth for all simulation parameters"
globs: ["**/*.py", "config.json"]
alwaysApply: true
---
# Configuration Management Rule
## Context
- Applies across all code that references configuration or simulation parameters.
- The `config.json` file is the **single source of truth** for:
- Agent stats (max_energy, max_hunger, decay rates, thresholds)
- Resource properties (decay rates, hunger/thirst/energy values)
- Action costs and success rates
- World parameters (dimensions, agent count, day/night cycles)
- Market settings (discounts, price multipliers)
- Economy parameters (ratios, thresholds, markup limits)
- UI settings (auto_step_interval)
## Requirements
1. **Never hardcode values** that exist or should exist in `config.json`.
2. When adding new features, add corresponding config entries to `config.json`.
3. Load config values at runtime using the existing config mechanism:
```python
from backend.config import Config
config = Config()
# Access via: config.agent_stats, config.resources, config.actions, etc.
```
4. Keep `config.json` synchronized with any code changes.
5. Always check `config.json` first before adding magic numbers to code.
## Examples
<example>
**Valid:**
```python
from backend.config import Config
config = Config()
max_energy = config.agent_stats["max_energy"]
hunt_success = config.actions["hunt_success"]
```
**Invalid:**
```python
max_energy = 50 # Hardcoded instead of using config
hunt_success = 0.70 # Magic number
```
</example>
## Project Structure Reference
- Backend code: `backend/` (API, core simulation, domain models)
- Frontend code: `frontend/` (client, renderers)
- Tools/utilities: `tools/` (analysis scripts, config converters)
- Documentation: `docs/design/`
- Logs output: `logs/`