Skip to content

Commit 10c19b7

Browse files
authored
Revise AGENTS.md for agent workflow guidelines
Updated the document to define agent workflow, execution principles, coding conventions, and prohibited actions for automated agents in the Rust repository. Signed-off-by: Xavier Lau <x@acg.box>
1 parent d9928cf commit 10c19b7

File tree

1 file changed

+280
-16
lines changed

1 file changed

+280
-16
lines changed

AGENTS.md

Lines changed: 280 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,293 @@
1-
# jwks-cache Development Guidelines
1+
# Agent Workflow
22

3-
Auto-generated from all feature plans. Last updated: 2025-11-01
3+
## Overview
44

5-
## Active Technologies
5+
This document defines the tooling rules, execution model, coding conventions, and hard restrictions that apply to all automated agents interacting with this Rust repository. Its purpose is to ensure reproducibility, consistent formatting, predictable behavior, and safe automation across the workspace.
66

7-
- Rust (stable, edition 2021) + `jsonwebtoken` 9.x, `reqwest` 0.12, `tokio` 1.x, `http-cache-semantics`, `tracing`, `metrics` facade with exporter adapters, optional `redis` feature, `wiremock` (tests) (001-build-jwks-cache)
7+
Agents must strictly follow every rule in this document when generating, modifying, or verifying source code or configuration.
88

9-
## Project Structure
9+
---
1010

11-
```text
12-
src/
13-
tests/
11+
# **1. Execution Principles**
12+
13+
## **1.1 Guiding Principle**
14+
15+
Agents must always use the curated `cargo make` tasks defined in `Makefile.toml` for all build, lint, format, test, and auxiliary operations.
16+
17+
Agents must **never** run raw `cargo` commands or manually invoke toolchains.
18+
19+
This guarantees:
20+
21+
- Correct toolchain selection
22+
- Consistent feature flags
23+
- Stable formatting and linting
24+
- No divergence from expected project behavior
25+
26+
---
27+
28+
## **1.2 Toolchain Notes**
29+
30+
- The repository pins the stable Rust toolchain via `rust-toolchain.toml`.
31+
- Certain tasks (e.g., formatting, some lint steps) require nightly, and the corresponding `cargo make` tasks already inject the correct version.
32+
- Agents must not alter toolchain definitions or configuration files.
33+
34+
---
35+
36+
## **1.3 Common Tasks**
37+
38+
- `cargo make clippy` — Lints the entire workspace under the expected feature matrix.
39+
- `cargo make fmt` — Formats the repository using the pinned nightly toolchain.
40+
- `cargo make nextest` — Runs the full test suite via nextest.
41+
42+
Agents must prefer these tasks over any raw `cargo` invocation.
43+
44+
---
45+
46+
## **1.4 Adding New Automation**
47+
48+
When introducing any new automation:
49+
50+
1. Define a dedicated task inside `Makefile.toml`.
51+
2. Document that task in this file so that all agents can use it.
52+
3. Always invoke the task via `cargo make <task>`.
53+
54+
---
55+
56+
# **2. Rust Coding Conventions**
57+
58+
These conventions apply to all crates and all directories (libraries, binaries, tests, examples, benches). They define the required structure and style of Rust source code.
59+
**Items that appear here do not appear again in the “Never Do” list to avoid duplication.**
60+
61+
---
62+
63+
## **2.1 Module, Import, and Declaration Order**
64+
65+
Each file must follow the strict declaration order:
66+
67+
```
68+
mod
69+
use
70+
macro_rules
71+
type
72+
const
73+
trait
74+
enum
75+
struct
76+
fn
1477
```
1578

16-
## Commands
79+
Within each group:
80+
81+
- `pub` items must appear before non-`pub` items.
82+
83+
Import section headers (e.g., `// std`, `// crates.io`, `// self`) must be preserved exactly and must not be removed.
84+
85+
---
86+
87+
## **2.2 Structs and Impl Blocks**
88+
89+
A struct’s `impl` must appear **immediately** after the struct definition with **no blank line** between them.
90+
91+
---
92+
93+
## **2.3 Generics, Bounds, and UFCS**
94+
95+
### Bound Placement
96+
97+
- All trait bounds must appear in a `where` clause.
98+
- Inline trait bounds after the generic list are not allowed.
99+
- Bounds must be ordered as:
100+
**(1) lifetimes → (2) standard library traits → (3) project traits**
101+
102+
### Generics
103+
104+
Whenever explicit generic type specification is required, agents must use turbofish syntax.
105+
106+
If turbofish cannot be used (e.g., `Into::into`), the explicit constructor form must be used instead.
107+
108+
### UFCS
109+
110+
Prefer UFCS (type-qualified paths) when referencing inherent items or specific trait implementations.
111+
112+
---
113+
114+
## **2.4 Borrowing Rules**
115+
116+
Prefer using plain references such as `&value` rather than `.as_ref()`, `.as_str()`, or similar adapters, unless the adapter is strictly required.
117+
118+
---
119+
120+
## **2.5 Macro, Formatting, and Logging Rules**
121+
122+
- Tracing macros must always be invoked with fully qualified paths (`tracing::info!`, etc.).
123+
- When using `format!`, tracing, or logging macros, directly reference existing variables in the format string.
124+
- Never introduce temporary variables solely for use inside a formatting expression.
125+
126+
---
127+
128+
# **3. Language Requirements**
129+
130+
These rules apply to:
131+
132+
- Comments
133+
- Documentation comments (`///` and `//!`)
134+
- Log messages
135+
136+
All such text must:
137+
138+
- Use standard, grammatically correct English.
139+
- Begin with capital letters and end with proper punctuation.
140+
- Avoid slang, localisms, and ambiguous abbreviations.
141+
- Avoid non-English languages completely in code-facing text.
142+
143+
---
144+
145+
# **4. Never Do**
146+
147+
The following actions are **strictly prohibited**. These rules ensure workspace integrity, prevent unpredictable behavior, and restrict agents to safe operational boundaries.
148+
149+
## **4.1 Toolchain and System Prohibitions**
150+
151+
### **(A) Never modify toolchain management files.**
152+
153+
Agents must not edit:
154+
155+
- `rust-toolchain.toml`
156+
- `.cargo/config.toml`
157+
- `rustfmt.toml`
158+
159+
### **(B) Never install, upgrade, or manually switch Rust toolchains.**
160+
161+
Prohibited commands include:
162+
163+
```
164+
rustup update
165+
rustup install ...
166+
rustup override ...
167+
```
168+
169+
### **(C) Never execute system-level installation commands.**
170+
171+
Prohibited:
172+
173+
```
174+
apt-get install ...
175+
brew install ...
176+
pip install ...
177+
```
178+
179+
---
180+
181+
## **4.2 File Boundary Restrictions**
182+
183+
### **(D) Never modify files outside the repository root.**
184+
185+
Agents must not touch:
186+
187+
- Parent directories
188+
- Home directories
189+
- Global system paths
190+
- External submodule files
191+
192+
### **(E) Never modify generated files.**
193+
194+
Including but not limited to:
195+
196+
- `OUT_DIR` outputs
197+
- `build.rs` generated files
198+
- `target/` directory
199+
- Vendored third-party code
200+
- Automatically generated assets or schemas
201+
202+
---
203+
204+
## **4.3 Patch and Diff Restrictions**
205+
206+
### **(F) Never produce non-unified diffs.**
207+
208+
Patch output must use standard unified diff format (`diff --git ...`).
209+
210+
### **(G) Never modify unrelated code in the same patch.**
211+
212+
Patches must be minimal and scoped exclusively to the user’s explicit request.
213+
214+
---
215+
216+
## **4.4 Style Restrictions**
217+
218+
### **(H) Never import tracing macros.**
219+
220+
Example of prohibited form:
221+
222+
```
223+
use tracing::{info, warn};
224+
```
225+
226+
Agents must always use:
227+
228+
```
229+
tracing::info!();
230+
```
231+
232+
### **(I) Never use inline trait bounds.**
233+
234+
(Prohibited under coding conventions; enforced again here as a hard rule.)
235+
236+
### **(J) Never place blank lines between a struct and its impl.**
237+
238+
### **(K) Never use `.as_ref()`, `.as_str()`, or similar adapters when `&value` suffices.**
239+
240+
---
241+
242+
## **4.5 Runtime and Async Restrictions**
243+
244+
### **(L) Never use `unwrap()` or `expect()` in non-test code.**
245+
246+
Unless the failure case is provably impossible (e.g., parsing a literal).
247+
248+
### **(M) Never block inside async contexts.**
249+
250+
Prohibited operations include:
251+
252+
```
253+
std::thread::sleep(...)
254+
blocking synchronous I/O
255+
```
256+
257+
---
258+
259+
## **4.6 Documentation and Language Restrictions**
260+
261+
### **(N) Never mix languages in comments, docs, or logs.**
262+
263+
### **(O) Never introduce ambiguous abbreviations or informal slang.**
264+
265+
Examples of prohibited shorthand:
266+
267+
- `w/`
268+
- `u`
269+
- `tho`
270+
- nonstandard contractions
271+
272+
---
273+
274+
## **4.7 Behavioral Restrictions**
275+
276+
### **(P) Never infer missing requirements.**
277+
278+
Agents may not guess intent or expand tasks beyond what is explicitly stated.
17279

18-
cargo test [ONLY COMMANDS FOR ACTIVE TECHNOLOGIES][ONLY COMMANDS FOR ACTIVE TECHNOLOGIES] cargo clippy
280+
### **(Q) Never apply optimizations or refactors unless explicitly asked.**
19281

20-
## Code Style
282+
This includes:
21283

22-
Rust (stable, edition 2021): Follow standard conventions
284+
- Code cleanup
285+
- Performance changes
286+
- Interface redesign
287+
- Removal of unused code
23288

24-
## Recent Changes
289+
---
25290

26-
- 001-build-jwks-cache: Added Rust (stable, edition 2021) + `jsonwebtoken` 9.x, `reqwest` 0.12, `tokio` 1.x, `http-cache-semantics`, `tracing`, `metrics` facade with exporter adapters, optional `redis` feature, `wiremock` (tests)
291+
# **5. Summary**
27292

28-
<!-- MANUAL ADDITIONS START -->
29-
<!-- MANUAL ADDITIONS END -->
293+
This document defines the complete execution workflow, toolchain usage rules, coding conventions, language standards, and prohibited actions for all automated agents operating within this Rust workspace. By adhering to these rules, agents ensure that generated code is consistent, predictable, maintainable, and safe to apply across the entire repository.

0 commit comments

Comments
 (0)