|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This document provides guidance for AI agents (e.g., GitHub Copilot, MCP servers, or LLM-based assistants) interacting with the Azure SDK for Rust repository. |
| 4 | + |
| 5 | +## Repository Overview |
| 6 | + |
| 7 | +### Purpose |
| 8 | + |
| 9 | +The Azure SDK for Rust provides Rust language bindings and client libraries for Azure services, following the [Azure SDK Design Guidelines for Rust](https://azure.github.io/azure-sdk/rust_introduction.html). |
| 10 | + |
| 11 | +### Status |
| 12 | + |
| 13 | +⚠️ Under active development. Large breaking changes may occur before 1.0 release. |
| 14 | + |
| 15 | +### Primary Language |
| 16 | + |
| 17 | +Rust (MSRV: 1.85) |
| 18 | + |
| 19 | +### Key Technologies |
| 20 | + |
| 21 | +- Rust toolchain with Cargo |
| 22 | +- TypeSpec for API specification and code generation |
| 23 | +- OpenTelemetry for distributed tracing |
| 24 | +- Test Proxy for recorded integration tests |
| 25 | + |
| 26 | +## Repository Structure |
| 27 | + |
| 28 | +``` |
| 29 | +. |
| 30 | +├── sdk/ # Service-specific crates organized by service |
| 31 | +│ └── <service>/ # Service directory (e.g., "keyvault", "storage") |
| 32 | +│ ├── <crate>/ # Service crate (e.g., "azure_security_keyvault_secrets") |
| 33 | +│ ├── assets.json # Pointer to test recordings (may be under <crate>/) |
| 34 | +│ ├── test-resources.bicep # Test resource definitions (may be under <crate>/) |
| 35 | +│ └── tsp-location.yaml # Pointer to TypeSpec in azure-rest-api-specs (may be under <crate>/) |
| 36 | +├── eng/ # Engineering system scripts and common tooling |
| 37 | +├── doc/ # Additional documentation |
| 38 | +├── .github/ |
| 39 | +│ ├── copilot-instructions.md # Copilot-specific Rust coding guidelines |
| 40 | +│ ├── instructions/ # Agent instruction files for specific tasks |
| 41 | +│ └── prompts/ # Reusable Copilot prompts |
| 42 | +├── CONTRIBUTING.md # Contribution guidelines (see for detailed workflows) |
| 43 | +└── README.md # Repository overview |
| 44 | +``` |
| 45 | + |
| 46 | +## Agent Capabilities |
| 47 | + |
| 48 | +### Recommended Actions |
| 49 | + |
| 50 | +AI agents can assist with: |
| 51 | + |
| 52 | +1. **Code Generation** |
| 53 | + - Writing new Rust code following repository conventions (see `.github/copilot-instructions.md`) |
| 54 | + - Generating unit tests using `#[cfg(test)]` modules |
| 55 | + - Creating integration tests with `#[recorded::test]` attributes (see `CONTRIBUTING.md` for details) |
| 56 | + - Generating documentation tests in `.rs` files (avoid `no_run` when tests can be run) |
| 57 | + - In README markdown files, use ` ```rust no_run` for examples with placeholders |
| 58 | + - Running `rustfmt` on all generated code to ensure proper formatting |
| 59 | + |
| 60 | +2. **Code Review Support** |
| 61 | + - Identifying potential bugs or safety issues |
| 62 | + - Suggesting improvements for idiomatic Rust patterns |
| 63 | + - Checking adherence to Azure SDK design guidelines |
| 64 | + - Reviewing error handling using `azure_core::Result<T>` |
| 65 | + |
| 66 | +3. **Documentation** |
| 67 | + - Improving inline documentation (using `///` doc comments) |
| 68 | + - Updating README files |
| 69 | + - Creating or updating CHANGELOG entries (see `.github/instructions/changelog.instructions.md`) |
| 70 | + - Writing hero scenario examples in doc comments (avoid examples in `examples/` directories unless demonstrating primary use cases) |
| 71 | + |
| 72 | +4. **Issue Triage** |
| 73 | + - Labeling issues with appropriate tags |
| 74 | + - Identifying duplicate issues |
| 75 | + - Suggesting relevant code owners based on `CODEOWNERS` |
| 76 | + - Summarizing issue discussions |
| 77 | + |
| 78 | +5. **Refactoring** |
| 79 | + - Applying clippy suggestions |
| 80 | + - Improving code organization and modularity |
| 81 | + - Updating dependencies in `Cargo.toml` |
| 82 | + - Consolidating imports (e.g., `use std::{borrow::Cow, marker::PhantomData};` instead of separate lines) |
| 83 | + |
| 84 | +### Restricted Actions |
| 85 | + |
| 86 | +AI agents **should not**: |
| 87 | + |
| 88 | +1. **Modify Generated Code** |
| 89 | + - Never edit files in `generated/` subdirectories |
| 90 | + - These are produced by TypeSpec code generators and will be overwritten |
| 91 | + - Instead, propose changes to TypeSpec specifications in [Azure/azure-rest-api-specs](https://github.com/Azure/azure-rest-api-specs) |
| 92 | + |
| 93 | +2. **Break API Compatibility** |
| 94 | + - Avoid introducing breaking changes without explicit approval |
| 95 | + - Check if changes affect public APIs before proceeding |
| 96 | + - Consider deprecation process (see `doc/deprecation-process.md`) |
| 97 | + |
| 98 | +3. **Bypass CI/CD Checks** |
| 99 | + - Do not suggest skipping or disabling CI checks |
| 100 | + - All code must pass `cargo build`, `cargo test`, and `cargo clippy` |
| 101 | + |
| 102 | +4. **Commit Secrets** |
| 103 | + - Never include credentials, keys, or tokens in code |
| 104 | + - Use environment variables for sensitive data |
| 105 | + - Sanitize test recordings to remove secrets |
| 106 | + |
| 107 | +5. **Modify Security or License Files** |
| 108 | + - Do not alter `SECURITY.md`, `LICENSE.txt`, or `CODE_OF_CONDUCT.md` without maintainer approval |
| 109 | + |
| 110 | +## Key Workflows |
| 111 | + |
| 112 | +### Building |
| 113 | + |
| 114 | +```bash |
| 115 | +# Build a specific crate |
| 116 | +cargo build -p <crate-name> |
| 117 | + |
| 118 | +# Build entire workspace (not recommended unless necessary) |
| 119 | +cargo build --workspace |
| 120 | +``` |
| 121 | + |
| 122 | +### Testing |
| 123 | + |
| 124 | +```bash |
| 125 | +# Run tests for a specific crate |
| 126 | +cargo test -p <crate-name> |
| 127 | + |
| 128 | +# Run integration tests with recordings |
| 129 | +cargo test -p <crate-name> --test <test-name> |
| 130 | + |
| 131 | +# Provision test resources (see CONTRIBUTING.md for details) |
| 132 | +eng/common/TestResources/New-TestResources.ps1 -ServiceDirectory <service> |
| 133 | + |
| 134 | +# Record new test sessions (requires provisioned resources) |
| 135 | +AZURE_TEST_MODE=record cargo test -p <crate-name> --test <test-name> |
| 136 | +``` |
| 137 | + |
| 138 | +See `CONTRIBUTING.md` for comprehensive testing guidance including debugging, Test Proxy usage, and trace logging. |
| 139 | + |
| 140 | +### Linting and Formatting |
| 141 | + |
| 142 | +```bash |
| 143 | +# Check for common issues |
| 144 | +cargo clippy -p <crate-name> |
| 145 | + |
| 146 | +# Auto-fix some issues |
| 147 | +cargo clippy --fix -p <crate-name> |
| 148 | + |
| 149 | +# Format code |
| 150 | +cargo fmt -p <crate-name> |
| 151 | +``` |
| 152 | + |
| 153 | +### Code Generation |
| 154 | + |
| 155 | +For crates with TypeSpec specifications: |
| 156 | + |
| 157 | +```bash |
| 158 | +cd sdk/<service>/<crate-name> |
| 159 | +tsp-client update |
| 160 | +``` |
| 161 | + |
| 162 | +### Running Examples |
| 163 | + |
| 164 | +```bash |
| 165 | +cargo run --package <crate-name> --example <example-name> |
| 166 | +``` |
| 167 | + |
| 168 | +## Coding Standards |
| 169 | + |
| 170 | +Agents should follow guidelines in `.github/copilot-instructions.md` and `CONTRIBUTING.md`, including: |
| 171 | + |
| 172 | +- **Naming Conventions**: |
| 173 | + - Types/variants: `PascalCase` |
| 174 | + - Functions/fields/parameters: `snake_case` |
| 175 | + - Constants: `UPPER_SNAKE_CASE` |
| 176 | + - Crates/modules: `snake_case` |
| 177 | + |
| 178 | +- **Import Style**: |
| 179 | + - Explicit imports (no `use foo::*`) |
| 180 | + - Consolidate related imports (e.g., `use std::{borrow::Cow, marker::PhantomData};`) |
| 181 | + - Prefer `crate::` for internal references |
| 182 | + |
| 183 | +- **Error Handling**: |
| 184 | + - Service crate code should return `azure_core::Result<T>` (where `E` defaults to `azure_core::Error`) |
| 185 | + - Use the `?` operator for error propagation |
| 186 | + - Examples should use `Result<(), Box<dyn std::error::Error>>` |
| 187 | + |
| 188 | +- **Documentation**: |
| 189 | + - All public APIs need `///` doc comments |
| 190 | + - Include runnable doc test examples where appropriate |
| 191 | + - Hero scenario examples under the `examples/` directory should have `#[tokio::main]` async main functions |
| 192 | + - Use absolute links in markdown files (e.g., `https://github.com/Azure/azure-sdk-for-rust/blob/main/AGENTS.md`) instead of relative links (e.g., `../AGENTS.md`) |
| 193 | + - Links must work both online (from github.com) and offline (when viewed in an IDE) |
| 194 | + |
| 195 | +- **Testing**: |
| 196 | + - Place unit tests in `#[cfg(test)] mod tests` |
| 197 | + - Use `#[recorded::test]` for integration tests (see `CONTRIBUTING.md`) |
| 198 | + - Test names should be descriptive, not prefixed with "test" |
| 199 | + |
| 200 | +## CI/CD Integration |
| 201 | + |
| 202 | +All pull requests trigger: |
| 203 | +- `cargo build` - Compilation check |
| 204 | +- `cargo test` - Unit and integration tests |
| 205 | +- `cargo clippy` - Lint checks |
| 206 | +- `cargo fmt --check` - Format validation |
| 207 | +- License/CLA verification |
| 208 | +- Code coverage analysis |
| 209 | + |
| 210 | +Integration tests use the Azure SDK Test Proxy for recording/playback. See `CONTRIBUTING.md` for Test Proxy setup and usage. |
| 211 | + |
| 212 | +## Safety and Security |
| 213 | + |
| 214 | +1. **Code Review**: All changes require review and approval from code owners |
| 215 | +2. **Static Analysis**: Must pass `cargo clippy` without warnings |
| 216 | +3. **Secret Scanning**: Automated checks prevent committing credentials |
| 217 | +4. **Dependencies**: Managed through workspace `Cargo.toml`, vetted for security |
| 218 | +5. **Vulnerability Reporting**: Via MSRC at <secure@microsoft.com> |
| 219 | + |
| 220 | +## Cross-References |
| 221 | + |
| 222 | +For detailed guidance, see: |
| 223 | + |
| 224 | +- **Rust Coding Guidelines**: `.github/copilot-instructions.md` |
| 225 | +- **Contribution Workflows**: `CONTRIBUTING.md` |
| 226 | +- **Changelog Guidelines**: `.github/instructions/changelog.instructions.md` |
| 227 | +- **Git Commit Standards**: `doc/git-commit-instructions.md` |
| 228 | +- **Deprecation Process**: `doc/deprecation-process.md` |
| 229 | +- **Azure SDK Design Guidelines**: https://azure.github.io/azure-sdk/rust_introduction.html |
| 230 | + |
| 231 | +## Agent-Specific Instructions |
| 232 | + |
| 233 | +Additional specialized instructions for specific workflows can be found in: |
| 234 | +- `.github/instructions/` - Task-specific agent instructions |
| 235 | +- `.github/prompts/` - Reusable Copilot prompts (use `#prompt` in Copilot) |
| 236 | + |
| 237 | +## Getting Help |
| 238 | + |
| 239 | +- **Issues**: https://github.com/Azure/azure-sdk-for-rust/issues |
| 240 | +- **Discussions**: Use issue comments or StackOverflow with `azure` + `rust` tags |
| 241 | +- **Code Owners**: See `.github/CODEOWNERS` for service-specific contacts |
| 242 | + |
| 243 | +## Telemetry and Privacy |
| 244 | + |
| 245 | +The SDK includes telemetry via `User-Agent` headers. Follow Microsoft Privacy Statement: https://go.microsoft.com/fwlink/?LinkID=824704 |
| 246 | + |
| 247 | +## License |
| 248 | + |
| 249 | +All contributions are licensed under the MIT License. See `LICENSE.txt`. |
| 250 | + |
| 251 | +--- |
| 252 | + |
| 253 | +**Last Updated**: 2025-01-20 |
| 254 | +**Version**: 1.0 |
| 255 | +**Canonical Spec**: https://agents.md |
0 commit comments