Skip to content

Commit ed45e96

Browse files
clean up agents
1 parent 875437b commit ed45e96

File tree

5 files changed

+97
-162
lines changed

5 files changed

+97
-162
lines changed

AGENTS.md

Lines changed: 97 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,57 @@ This repository contains the **executable code for the Pioreactor project**. It
55
1. `core/` — backend / worker code that runs jobs. Important files:
66
- `core/pioreactor/background_jobs/base.py` is the super class for background jobs (like stirring, od_reading, automations, etc)
77
2. `core/pioreactor/web/` — Flask-based web API. Important files:
8-
- `core/pioreactor/web/api.py` handles the leader-only (and frontend) api. This is the main entry point most often. It sends requests to the `unit_api.py` too.
9-
- `core/pioreactor/web/unit_api.py` is the pioreactor-specific api for controlling individual actions on a Pioreactor.
10-
- `core/pioreactor/web/tasks.py` lists the Huey (background) tasks spawned by the web apis.
8+
- `core/pioreactor/web/api.py` handles the leader-only (and frontend) API. This is the main entry point most often. It sends requests to `unit_api.py` too.
9+
- `core/pioreactor/web/unit_api.py` is the pioreactor-specific API for controlling individual actions on a Pioreactor.
10+
- `core/pioreactor/web/tasks.py` lists the Huey (background) tasks spawned by the web APIs.
1111
3. `frontend/` — React-based web UI
1212

1313
---
1414

15-
## Running the System
15+
## Key components
16+
17+
* **Background Jobs**
18+
Long-running tasks inherit from `BackgroundJob` in `core/pioreactor/background_jobs/base.py`. Examples include stirring control (`stirring.py`), optical density readings (`od_reading.py`), temperature automation, dosing automation.
19+
20+
* **Automations**
21+
Higher-level automation logic derives from `AutomationJob` in `core/pioreactor/automations/base.py`. Dosing, temperature, and LED automations are implemented under `core/pioreactor/automations/`.
22+
23+
* **Command-Line Interface**
24+
The `pio` CLI in `core/pioreactor/cli/pio.py` provides commands to run jobs, adjust settings, view logs, and update software. It checks for first-boot success and ensures the user is not running as root.
25+
26+
* **Configuration System**
27+
Configuration is loaded through `get_config()` in `core/pioreactor/config.py`, which merges global and unit-specific files and creates additional sections like `PWM_reverse`. A sample development config is provided in `config.dev.ini` with settings for PWM channels, stirring parameters, OD reading, MQTT broker, UI options, and more.
28+
29+
* **Hardware Utilities**
30+
`core/pioreactor/hardware.py` defines GPIO pin mappings and I2C addresses depending on hardware version. Modules in `core/pioreactor/utils/` implement PWM control, ADC/DAC access, temperature sensors, and network helpers.
31+
32+
* **Data Structures and Messaging**
33+
Typed message structures for MQTT communication—such as `ODReadings`, `DosingEvent`, and `CalibrationBase`—are defined in `core/pioreactor/structs.py`.
34+
35+
* **Version and Device Info**
36+
Software version and hardware detection logic reside in `pioreactor/version.py`, exposing `__version__` and helper functions like `get_hardware_version()`.
37+
38+
* **Plugin System**
39+
Additional functionality can be loaded via Python entry points or drop-in `.py` files under `~/.pioreactor/plugins`. Plugins are discovered and registered in `pioreactor/plugin_management/__init__.py`.
40+
41+
* **Web API and UI**
42+
The `core/pioreactor/web/` directory includes our APIs and built frontend React projects.
43+
44+
---
45+
46+
## Running the system
1647

1748
ALWAYS use the project virtualenv for any Python or pytest commands:
1849

1950
```bash
2051
source .venv/bin/activate
2152
```
2253

54+
We use Python 3.13.
55+
2356
**Startup order (recommended):**
2457

2558
0. Before starting anything, run `make dev-status` to see whether the Huey consumer, Flask API (4999), or frontend dev server (3000) are already up. Only launch what's listed under "Need to start".
26-
2759
1. Start the Huey consumer:
2860

2961
```bash
@@ -43,20 +75,22 @@ source .venv/bin/activate
4375

4476
```bash
4577
pio run XYZ
78+
pio kill --job-name XYZ
4679
```
4780

81+
Some jobs might be blocking and long-running, so use the background feature of your harness to not block.
82+
4883
---
4984

50-
## Tools & Commands
85+
## Tools & commands
5186

5287
Available commands are listed in the `Makefile`. Key ones:
5388

5489
```bash
5590
make dev-status # Summarizes which dev servers are already running vs need to be started
56-
make tail-log # Show last 10 lines of the merged pioreactor log (override with LINES=200)
57-
make huey-dev # Run Huey consumer with dev flags
58-
make web-dev # Run Flask API on 127.0.0.1:4999
59-
make frontend-dev # Run React dev server on 127.0.0.1:3000
91+
make huey-dev # Run Huey consumer with dev flags
92+
make web-dev # Run Flask API on 127.0.0.1:4999
93+
make frontend-dev # Run React dev server on 127.0.0.1:3000
6094
```
6195

6296
`make dev-status` either reports "All dev services appear to be running" with brief details, or prints a "Need to start" list with only the missing services. Start only those listed; everything else is already running.
@@ -65,7 +99,7 @@ make frontend-dev # Run React dev server on 127.0.0.1:3000
6599

66100
## Testing
67101

68-
* Use **pytest** for Python tests. However, all the tests take in excess of 30 minutes, so don't run the entire test suite. Instead run specific files or tests using pytest options.
102+
* Use **pytest** for Python tests. All tests take in excess of 30 minutes, so don't run the entire test suite. Instead run specific files or tests using pytest options.
69103

70104
```bash
71105
.venv/bin/pytest core/tests/test_cli.py
@@ -76,37 +110,72 @@ make frontend-dev # Run React dev server on 127.0.0.1:3000
76110
## Logging
77111

78112
* All logs are written to **`pioreactor.log`**.
79-
* To view logs:
113+
* To view recent logs:
80114

81115
```bash
82-
make tail-log
116+
pio logs -n 10
83117
```
84118

85119
---
86120

87-
## Search & Navigation
121+
## MQTT
88122

89-
When searching the repo:
123+
We make use a mosquitto MQTT. Try `pio mqtt` to get a feed, or subset with `pio mqtt -t "your topic"`.
90124

91-
* **Exclude** these directories:
125+
---
92126

93-
* `core/tests/data/`
94-
* `core/update_scripts/`
127+
## Search & navigation
95128

96-
* **Exclude** all `CHANGELOG.md` files.
129+
When searching the repo, exclude these directories:
97130

98-
## CI
131+
* `core/tests/data/`
132+
* `core/update_scripts/`
133+
* `migration_scripts/`
134+
* `tests/data`
135+
* `update_scripts/`
136+
* `experiments/`
137+
* `jupyer_notebooks/`
99138

100-
We run github actions for our CI, located in `.github/workflows/ci.yaml`
139+
Also exclude all `CHANGELOG.md` files.
140+
141+
---
142+
143+
## CI
144+
145+
We run GitHub Actions for CI, located in `.github/workflows/ci.yaml`.
146+
147+
---
148+
149+
## Important filesystem locations
150+
151+
- `.pioreactor/config.ini` contains development configuration parameters.
152+
- `.pioreactor/plugins/` is where Python plugin files (`*.py`) can be added.
153+
- `.pioreactor/experiment_profiles/` stores experiment profiles in YAML format.
154+
- `.pioreactor/storage/` holds the main database, backups, and caches.
155+
- `.pioreactor/storage/calibrations/` stores calibration data.
156+
- `.pioreactor/storage/estimators/` stores estimator data.
157+
158+
---
101159

102160
## Business logic
103161

104162
Make sure to consider the following when editing and reviewing code.
105163

106-
- One of the Raspberry Pi's is assigned as the "leader", and this hosts most of the services: web server, MQTT broker, database, etc. It also sends commands to any "workers". The leader can also be a worker. Together, the leader and all the workers are called a "cluster". A cluster can be a small as a single leader+worker. Pioreactors are assigned to be a leader, worker, or both based on the custom image they install.
107-
- Different jobs, like stirring, OD reading, dosing, etc. are controlled by separate Python objects. Some jobs will passively listen for events from other jobs, and change their behavior in response, for example, dosing automations listen to OD readings, and may respond by dosing or not dosing.
108-
- The main "control plane" for the Pioreactor software is the command line interface, pio. For example, when the user starts a activity from the UI, the web server will run `pio run X ...`, which launches a Python process that will instantiate the object the controls the activity.
109-
- Because each activity is a separate Python process, we can modify an activity before running it by changing files on the filesystem.
110-
- The Raspberry Pis / Pioreactors communicate through the local network (in more advanced cases, this network is hosted on the leader). Users control the Pioreactor cluster while being on the same network, and accessing the web UI or the command line of the Pioreactors.
111-
- Leaders talk to Pioreactors via http requests between their respective web servers (using lighttpd + Flask, on port 80 by default). Workers send experiment data back to the leader via MQTT (see below). We expect users to control the leader only (using the web interface or CLI), and let the leader control the workers (there are exceptions).
112-
- The Pioreactor UI also connects to MQTT, and uses it to push and pull live data from the activities in each Pioreactor (states of activities, settings, graphs, etc).
164+
- One of the Raspberry Pi's is assigned as the "leader", and this hosts most of the services: web server, MQTT broker, database, etc. It also sends commands to any "workers". The leader can also be a worker. Together, the leader and all the workers are called a "cluster". A cluster can be a small as a single leader+worker. Pioreactors are assigned to be a leader, worker, or both based on the custom image they install.
165+
- Different jobs, like stirring, OD reading, dosing, etc. are controlled by separate Python objects. Some jobs will passively listen for events from other jobs, and change their behavior in response, for example, dosing automations listen to OD readings, and may respond by dosing or not dosing.
166+
- The main "control plane" for the Pioreactor software is the command line interface, pio. For example, when the user starts a activity from the UI, the web server will run `pio run X ...`, which launches a Python process that will instantiate the object the controls the activity.
167+
- Because each activity is a separate Python process, we can modify an activity before running it by changing files on the filesystem.
168+
- The Raspberry Pis / Pioreactors communicate through the local network (in more advanced cases, this network is hosted on the leader). Users control the Pioreactor cluster while being on the same network, and accessing the web UI or the command line of the Pioreactors.
169+
- Leaders talk to Pioreactors via HTTP requests between their respective web servers (using lighttpd + Flask, on port 80 by default). Workers send experiment data back to the leader via MQTT (see below). We expect users to control the leader only (using the web interface or CLI), and let the leader control the workers (there are exceptions).
170+
- The Pioreactor UI also connects to MQTT, and uses it to push and pull live data from the activities in each Pioreactor (states of activities, settings, graphs, etc).
171+
172+
---
173+
174+
## Purpose and usage
175+
176+
The Pioreactor software enables users to control and monitor small-scale bioreactors. It supports features such as:
177+
178+
* Running stirring, optical density measurement, and dosing automatically.
179+
* Managing a cluster of Pioreactors via MQTT and HTTP APIs.
180+
* Applying calibrations for pumps, stirring, and OD readings.
181+
* Scheduling complex experiment profiles that coordinate multiple jobs across workers.

core/AGENTS.md

Lines changed: 0 additions & 101 deletions
This file was deleted.

core/Makefile

Lines changed: 0 additions & 30 deletions
This file was deleted.

core/pioreactor/experiment_profiles/AGENTS.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

core/pioreactor/web/AGENTS.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Key modules:
1717
* **`utils.py`** – Helper utilities for caching responses, rate limiting, and validating filenames.
1818

1919

20-
21-
2220
The repository also includes a compiled frontend in the `static/` directory and startup scripts (`fcgi.py`).
2321

2422
Overall, the project provides a REST API and task queue framework to manage Pioreactor clusters, interact with hardware via CLI commands, and expose data/logs to a web UI.

0 commit comments

Comments
 (0)