| 1 |
# Coding Agent Guide (dirsearch) |
| 2 |
|
| 3 |
This repository contains **dirsearch**, a web path discovery tool. Use this guide to keep changes aligned with project expectations and release workflows. |
| 4 |
|
| 5 |
## Scope |
| 6 |
- These instructions apply to the entire repository. |
| 7 |
- If a subdirectory contains its own `AGENTS.md`, that file takes precedence for that subtree. |
| 8 |
|
| 9 |
## Project overview (high-level map) |
| 10 |
- **Entrypoint**: `dirsearch.py` is the CLI entry for running scans. |
| 11 |
- **Core flow**: `lib/controller/controller.py` orchestrates scans, sets up reports, handles sessions, and manages runtime flow. |
| 12 |
- **Networking**: `lib/connection/requester.py` (sync) and `lib/connection` modules manage HTTP requests, proxies, auth, rate limiting, and DNS caching. |
| 13 |
- **Reporting**: `lib/report/` and `lib/report/manager.py` manage output formats (plain, JSON, XML, CSV, HTML, SQLite, MySQL, PostgreSQL, etc.). |
| 14 |
- **Sessions**: session persistence is handled by `lib/controller/session.py`, with default session paths configured in `lib/core/settings.py`. |
| 15 |
- **Builds**: PyInstaller build files live under `pyinstaller/`, with CI workflows under `.github/workflows/`. |
| 16 |
- **Docker**: `Dockerfile` provides a minimal containerized entrypoint. |
| 17 |
|
| 18 |
## Directory structure (quick map) |
| 19 |
- `lib/`: Core application code (modules grouped by responsibility). |
| 20 |
- `lib/core/`: settings, options, data, and shared helpers. |
| 21 |
- `lib/controller/`: orchestration and session handling. |
| 22 |
- `lib/connection/`: HTTP/DNS/networking stack. |
| 23 |
- `lib/parse/`: parsing helpers (URLs, raw requests). |
| 24 |
- `lib/report/`: reporting formats and output handlers. |
| 25 |
- `lib/utils/`: utility modules shared across the codebase. |
| 26 |
- `lib/view/`: terminal output and UI helpers. |
| 27 |
- `db/`: bundled wordlists and categories. |
| 28 |
- `tests/`: test data and unit tests. |
| 29 |
- `sessions/`: default session output location for source runs. |
| 30 |
- `static/`: static assets (logos). |
| 31 |
- `.github/workflows/`: CI/CD, security scanning, and packaging workflows. |
| 32 |
|
| 33 |
## Code style and architecture |
| 34 |
- Prefer **pythonic** code: clear naming, readable structure, and small, testable functions. |
| 35 |
- Use **polymorphism and classes** where it improves readability or flexibility (especially within `lib/`), avoiding unnecessary complexity. |
| 36 |
- Treat `lib/` as a modular framework: keep boundaries clean, use explicit interfaces, and avoid cross-layer leakage. |
| 37 |
- Add **comments for edge cases** so behavior is clear to future maintainers. |
| 38 |
|
| 39 |
## When you change X, check Y (dependency map) |
| 40 |
Use this section to keep side effects aligned and to avoid missing required updates. |
| 41 |
|
| 42 |
### CLI / options / config |
| 43 |
- If you add or change CLI options, update: |
| 44 |
- `README.md` options/usage docs. |
| 45 |
- `config.ini` defaults (when relevant). |
| 46 |
- Any tests or examples referencing the old flags. |
| 47 |
|
| 48 |
### Output formats / reports |
| 49 |
- If you add or change report formats: |
| 50 |
- Update `lib/report/manager.py` to register the handler. |
| 51 |
- Confirm the format appears in README output examples if documented. |
| 52 |
- Ensure any CI tests that generate reports still pass (see `.github/workflows/ci.yml`). |
| 53 |
|
| 54 |
### Sessions |
| 55 |
- If you change session content or schema: |
| 56 |
- Update `lib/controller/session.py` serialization/deserialization logic. |
| 57 |
- Update any references to default session locations in docs (see `README.md`). |
| 58 |
- Consider backward compatibility for older session formats. |
| 59 |
|
| 60 |
### Networking / request pipeline |
| 61 |
- If you modify request logic, proxies, auth, or rate limiting: |
| 62 |
- Review `lib/connection/requester.py` and `lib/connection/dns.py`. |
| 63 |
- Validate behavior with relevant CLI options (proxy, auth, random agents, max rate). |
| 64 |
- Consider updates to tests or example commands in CI. |
| 65 |
|
| 66 |
### Controller / workflow behavior |
| 67 |
- If you change scan orchestration or run flow: |
| 68 |
- Review `lib/controller/controller.py` for session handling, callbacks, and report preparation. |
| 69 |
- Ensure that report saving and session export still operate as expected. |
| 70 |
|
| 71 |
### Build & release artifacts (PyInstaller) |
| 72 |
- If you add modules or dependencies that must be bundled: |
| 73 |
- Update PyInstaller hidden imports or data in: |
| 74 |
- `pyinstaller/dirsearch.spec` (preferred), and |
| 75 |
- GitHub Actions PyInstaller workflows under `.github/workflows/` (Linux/macOS/Windows). |
| 76 |
- Verify `pyinstaller/build.sh` still produces a working binary. |
| 77 |
- If you change outputs or binary names, update the release workflow (`pyinstaller-release-draft.yml`). |
| 78 |
|
| 79 |
### Docker |
| 80 |
- If you add OS-level dependencies or change runtime behavior: |
| 81 |
- Update `Dockerfile` accordingly. |
| 82 |
- Ensure new files are included in the container build context. |
| 83 |
|
| 84 |
### CI / GitHub Actions |
| 85 |
- If you change dependencies, CLI usage, or tests: |
| 86 |
- Update `.github/workflows/ci.yml` to keep inspection steps and command flags in sync. |
| 87 |
- Consider whether CodeQL, Semgrep, Docker build, or PyInstaller workflows need updates. |
| 88 |
|
| 89 |
### Adding a new feature or major behavior |
| 90 |
- Update docs (`README.md`, CLI examples, and any new flags). |
| 91 |
- Ensure reports/session outputs include the new data if applicable. |
| 92 |
- Verify CI commands still cover the new feature path. |
| 93 |
- Consider whether Docker, PyInstaller, or release workflows need updates for new dependencies or files. |
| 94 |
|
| 95 |
## Current automation (quick reference) |
| 96 |
- **CI / Inspection**: `.github/workflows/ci.yml` runs CLI scans, `testing.py`, lint (flake8), and codespell. |
| 97 |
- **Security**: CodeQL (`codeql-analysis.yml`) and Semgrep (`semgrep-analysis.yml`) run on PRs/pushes. |
| 98 |
- **Docker**: `docker-image.yml` builds the Docker image on pushes and PRs to `master`. |
| 99 |
- **PyInstaller**: platform builds and draft release workflows live under `.github/workflows/pyinstaller-*.yml`. |
| 100 |
|
| 101 |
## Testing guidance |
| 102 |
- For logic changes, try: |
| 103 |
- `python3 testing.py` |
| 104 |
- `python3 -m pytest` (if you touch tests or add new ones) |
| 105 |
- For CLI changes, run a short scan against a sample target: |
| 106 |
- `python3 dirsearch.py -w ./tests/static/wordlist.txt -u https://example.com -q` |
| 107 |
|
| 108 |
## Communication checklist (for summaries / PRs) |
| 109 |
- What changed and why. |
| 110 |
- Any updates to docs, CLI flags, or output formats. |
| 111 |
- Whether sessions or reports were affected (and if a migration is required). |
| 112 |
- Tests executed and their results. |