|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +## Scope and source of truth |
| 4 | +- Work in the top-level tree (`/scapy`), not the vendored release snapshot (`/scapy-2.7.1.dev...`) or `build/` artifacts. |
| 5 | +- Start with `README.md`, `CONTRIBUTING.md`, `tox.ini`, and `test/run_tests` before changing behavior. |
| 6 | + |
| 7 | +## Big-picture architecture |
| 8 | +- Public API aggregation is import-driven: `scapy/all.py` pulls core modules, then `scapy/layers/all.py` autoloads layer modules from `conf.load_layers` (`scapy/config.py`). |
| 9 | +- Core packet model is `Packet` (`scapy/packet.py`): layers are stacked with `/`, dissection/build behavior hangs off `fields_desc`, `payload_guess`, and `post_build`. |
| 10 | +- Layer binding is declarative and two-way via `bind_layers()` / `split_layers()` (`scapy/packet.py`); this controls both build-time field overloading and dissect-time next-layer guessing. |
| 11 | +- Runtime/CLI bootstrapping lives in `scapy/main.py` (`interact`, `load_layer`, `load_contrib`, extension loading). |
| 12 | +- Platform socket backends are selected centrally in `scapy/config.py` (`conf.use_pcap`, `conf.use_bpf`, OS-specific `scapy/arch/*`). |
| 13 | + |
| 14 | +## Where to place new code |
| 15 | +- Common protocols -> `scapy/layers/`; uncommon/vendor-specific -> `scapy/contrib/` (see `CONTRIBUTING.md`). |
| 16 | +- `scapy/layers/*` must not import `scapy/contrib/*`; `contrib` may import either. |
| 17 | +- Contrib modules must declare metadata headers near the top, e.g. in `scapy/contrib/automotive/scanner/graph.py`: |
| 18 | + - `# scapy.contrib.description = ...` |
| 19 | + - `# scapy.contrib.status = ...` |
| 20 | + |
| 21 | +## Developer workflows that match CI |
| 22 | +- Fast local baseline (no extra external tools): `./test/run_tests` |
| 23 | +- Direct UTScapy run with config file: `python -m scapy.tools.UTscapy -c test/configs/linux.utsc` |
| 24 | +- Lint/type/docs parity with CI: `tox -e flake8`, `tox -e mypy`, `tox -e docs`, `tox -e spell` |
| 25 | +- Full matrix behavior is driven by `.github/workflows/unittests.yml` + `.config/ci/test.sh` (keyword skips via `UT_FLAGS`, root/non-root split, OS-specific toggles). |
| 26 | + |
| 27 | +## Project-specific conventions |
| 28 | +- Keep hot-path core changes lean (`scapy/packet.py`, `scapy/base_classes.py`): performance and allocation overhead matter. |
| 29 | +- Logging policy is strict (`CONTRIBUTING.md`): prefer `scapy.error.log_runtime` for runtime behavior; use `log_interactive` only for interactive-shell-only messages. |
| 30 | +- Test style is UTScapy-first (`test/*.uts`, `test/scapy/**/*.uts`): last expression decides pass/fail; keyword include/exclude (`-k` / `-K`) is heavily used. |
| 31 | +- Preserve SPDX/license headers and existing typing-comment style (`# type:`) where present. |
| 32 | + |
| 33 | +## Integration points and dependencies |
| 34 | +- Optional features are capability-gated in `scapy/config.py` (notably `cryptography`, libpcap/bpf selection, extension manager `conf.exts`). |
| 35 | +- Some features depend on external binaries configured via `conf.prog` (`tcpdump`, `tshark`, `wireshark`, `dot`). |
| 36 | +- Docs and API tree are Sphinx-based (`doc/scapy/`, `tox -e docs`, `tox -e apitree`). |
| 37 | +- Test selection/behavior depends on `test/configs/*.utsc` preexec hooks (for example loading `tls` or contrib modules before campaigns). |
| 38 | + |
0 commit comments