Skip to content

Latest commit

 

History

History
145 lines (99 loc) · 4.33 KB

File metadata and controls

145 lines (99 loc) · 4.33 KB

AGENTS.md

This repository is a small Rust reverse proxy server (Axum + Reqwest). Use this file as the primary guidance for automated agents working here.

Scope

  • Keep changes minimal and idiomatic to this codebase.
  • Prefer explicit, readable code over cleverness.
  • Avoid adding dependencies unless necessary; keep Cargo.toml lean.

Required/Existing Rules

  • No Cursor rules found in .cursor/rules/ or .cursorrules.
  • No Copilot rules found in .github/copilot-instructions.md.

If new rules are added later, incorporate them here.

Build, Lint, Test

Common commands (run from repo root):

# Build (debug)
cargo build

# Build (release)
cargo build --release

# Run (needs config file)
cargo run -- -c /path/to/config.toml

# Format (Rust standard formatting)
cargo fmt

# Lint (Clippy)
cargo clippy --all-targets --all-features -- -D warnings

# Test suite
cargo test

Running a single test (if/when tests exist):

# By test name substring
cargo test <test_name_substring>

# Integration test file
cargo test --test <test_file_name_without_rs>

# Unit tests in a specific module
cargo test <module_path>::<test_name>

If tests are added later, update this section with project-specific commands.

Project Layout

  • src/main.rs: entrypoint and logging setup.
  • src/config.rs: config file parsing/validation and CLI args.
  • src/run.rs: server setup and Axum routing composition.
  • src/proxy.rs: proxy routing logic and request forwarding.
  • src/error.rs: minimal error type and Result alias.

Code Style Guidelines

Imports and Module Structure

  • Use grouped, sorted imports similar to existing files:
    • std imports first
    • third-party imports next
    • crate imports last
  • Prefer explicit use of types/modules used in a file.
  • Avoid wildcard imports except when already common in Axum patterns.

Formatting

  • Run cargo fmt after edits.
  • Keep line lengths reasonable; prefer line breaks over horizontal scrolling.
  • Use Rust 2024 edition conventions; do not introduce deprecated patterns.

Naming Conventions

  • Modules: snake_case (files already follow this).
  • Types/structs/enums: PascalCase.
  • Functions/variables: snake_case.
  • Constants: SCREAMING_SNAKE_CASE.
  • Avoid abbreviations unless already used in the codebase (cfg, req).

Types and Ownership

  • Favor concrete types for public APIs; avoid unnecessary generics.
  • Prefer borrowing (&str, &T) unless ownership is needed.
  • Clone only when necessary; e.g., reqwest::Client is cheap to clone.
  • Use Option and Result to model fallible or optional behavior.

Error Handling

  • Use the crate Result<T> alias (src/error.rs).
  • Convert errors into Error::AnyError via ? or into().
  • Provide clear, actionable error messages (see config validation).
  • For HTTP errors, use appropriate StatusCode values and readable bodies.

Logging and Tracing

  • Use tracing for diagnostics (info, debug, etc.).
  • Respect RUST_LOG_MAX behavior in src/main.rs.
  • Avoid logging sensitive data (auth headers, tokens).

HTTP/Proxy Behavior

  • Preserve existing header forwarding rules unless intentionally changing behavior.
  • When adding headers, be explicit about reasons and scope.
  • Keep proxy path rewrites consistent with source_path -> dest_path.
  • Do not enable WebSocket behavior unless explicitly requested.

Config and CLI

  • Config is TOML (config.toml) and required to run.
  • Config::build performs minimal validation; maintain or extend as needed.
  • CLI uses clap derive; add new flags in Args with clear doc comments.

Testing Guidance

  • If you add tests, prefer #[tokio::test] for async code.
  • Unit tests can live next to modules; integration tests in tests/.
  • Keep tests deterministic; mock external HTTP calls where possible.

Dependency Guidance

  • Prefer standard library and existing dependencies first.
  • New deps require justification and should be minimal in scope.
  • If adding a dev-only tool, use [dev-dependencies].

Agent Safety

  • Do not modify config-example.toml unless required by a feature.
  • Avoid changing behavior unrelated to the requested task.
  • If a change impacts runtime behavior (routing, headers, auth), document it.

Notes for Future Agents

  • There is no CI config or task runner; use cargo commands directly.
  • This project is intentionally simple; keep it that way.