WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 0f04940

Browse files
authored
Merge pull request #486 from unoplatform/dev/jela/agents
chore: Add agents file
2 parents 5902fce + dd2b4b9 commit 0f04940

File tree

1 file changed

+269
-0
lines changed

1 file changed

+269
-0
lines changed

AGENTS.md

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
# AI Agents Contribution & Coding Instructions
2+
3+
This document defines strict guardrails for any AI-assisted or automated agent contributions (including Copilot, custom prompt runners, or scripted refactors). Human contributors must also ensure generated changes comply before merge.
4+
5+
---
6+
7+
## 1. Core Engineering Principles
8+
9+
✅ Apply all SOLID principles (SRP, OCP, LSP, ISP, DIP).
10+
✅ Keep code simple, intention‑revealing; clarity > cleverness.
11+
✅ Separate concerns: validation | storage | processing | error handling | presentation.
12+
✅ Favor composition over inheritance; inject abstractions, not concretes.
13+
✅ Optimize only with evidence (profiling/metrics).
14+
15+
---
16+
17+
## 2. Performance & Allocations
18+
19+
✅ Minimize allocations in hot paths (e.g. use `StringBuilder` for server-side string assembly).
20+
✅ Avoid unnecessary LINQ in tight loops; prefer explicit loops where critical.
21+
✅ Use `readonly` on fields and structs where possible.
22+
✅ Avoid boxing (watch generics, interpolated logging with value types).
23+
✅ Reuse `HttpClient`, `JsonSerializerOptions`, buffers.
24+
✅ Only introduce `Span<T>` / `Memory<T>` when profiling shows benefit.
25+
26+
---
27+
28+
## 3. Framework & Platform Usage
29+
30+
✅ Apply `CancellationToken` to all async public APIs and I/O boundaries.
31+
✅ Avoid `.Result` / `.GetAwaiter().GetResult()` outside controlled sync bridging points.
32+
✅ Prefer non-blocking async flow (no `.GetAwaiter().GetResult()` / blocking waits) to remain WASM-safe; if a sync bridge is unavoidable, document why and keep it local.
33+
✅ External integrations abstracted behind interfaces for testability.
34+
35+
---
36+
37+
## 4. Build & Validation
38+
39+
Solution: `Uno.Check.sln`
40+
41+
### Local Build (PowerShell)
42+
43+
```pwsh
44+
# Restore dependencies
45+
dotnet restore Uno.Check.sln
46+
47+
# Debug build (warnings allowed temporarily)
48+
dotnet build Uno.Check.sln -c Debug
49+
50+
# Release build MUST be 100% clean
51+
dotnet build Uno.Check.sln -c Release "/clp:WarningsOnly;Summary"
52+
```
53+
54+
✅ Zero warnings in Release is mandatory.
55+
✅ Suppress a warning only with justification in PR + targeted scope (`#pragma` with comment).
56+
✅ Do not disable deterministic builds.
57+
✅ Avoid expanding global `<NoWarn>` unless approved.
58+
59+
## 5. Workloads updates process
60+
61+
In order to update the workloads manifest to the latest version, you need to:
62+
63+
- Install the latest (or otherwise specified by user directives) .NET in a custom folder, in order to avoid inheriting the build agent's .NET SDK
64+
- Install the following workloads:
65+
66+
```bash
67+
dotnet workload install ios android maui catalyst tvos wasm-tools
68+
```
69+
- Get the installed workloads list:
70+
71+
```bash
72+
dotnet workload list
73+
```
74+
75+
- Update the relevant files with the new .NET SDK version and workload versions, based on the requested version:
76+
- `manifests/uno.ui.manifest.json` for the current .NET SDK stable release
77+
- `manifests/uno.ui-preview.manifest.json` for the current .NET SDK major preview release
78+
- `manifests/uno.ui-preview-major.manifest.json` for the next major .NET SDK preview release
79+
80+
## 5. Testing Requirements
81+
82+
✅ Every new public behavior must include tests (unit and/or integration).
83+
✅ Namespace parity: implementation namespaces mirrored in `*.Tests` projects.
84+
✅ AAA pattern (Arrange / Act / Assert).
85+
✅ Deterministic fakes for time, GUID, randomness.
86+
✅ Favor lightweight in-memory substitutes over heavy mocks.
87+
✅ Lack of coverage for new logic blocks merge.
88+
89+
### Minimum Test Additions Per PR
90+
91+
| Change Type | Required Tests |
92+
|-------------|----------------|
93+
| New service/class | Happy path + 1 failure/edge case |
94+
| New DTO or mapping | Round‑trip / validation scenario |
95+
| Bug fix | Repro test + non‑regression guard |
96+
97+
### String equivalence assertions (multiline)
98+
- Use raw strings (`"""..."""`) for expected and actual samples.
99+
- Prefer `.Should().BeEquivalentTo(expected, o => o.IgnoringNewlineStyle())` for multiline string comparisons;
100+
- Avoid manual newline normalization (`Replace("\r\n", "\n")`, `NormalizeLineEndings()`); rely on the AwesomeAssertions (fork of FluentAssertions) options instead.
101+
102+
### Run Tests
103+
104+
```pwsh
105+
# Full suite
106+
dotnet test Uno.Check.sln --no-build -c Debug
107+
108+
# Optional coverage (if configured)
109+
dotnet test Uno.Check.slnx -c Debug /p:CollectCoverage=true /p:CoverletOutputFormat=lcov
110+
```
111+
112+
✅ Maintain or improve passing test count
113+
✅ Never delete tests without equivalent protection.
114+
115+
---
116+
117+
## 6. DTO & API Conventions
118+
119+
✅ Prefer immutable DTOs (constructor + init).
120+
✅ Don’t expose domain entities directly.
121+
✅ Centralize validation (FluentValidation or data annotations).
122+
✅ Version for additive change; avoid breaking removals.
123+
✅ Persisted enums: explicit underlying type; external protocols may prefer strings.
124+
125+
---
126+
127+
## 7. Dependency Injection
128+
129+
✅ Correct lifetimes: `Scoped` for request logic, `Singleton` only if stateless/thread-safe, `Transient` for lightweight.
130+
✅ Constructor injection only (no service locator).
131+
✅ Keep constructor params under control (< 7 ideal); refactor into options/aggregates if larger.
132+
✅ Interfaces for externally consumed abstractions; skip when internal-only.
133+
134+
---
135+
136+
## 8. Logging & Diagnostics
137+
138+
✅ Structured logging (`logger.LogInformation("Processed {Id}", id)`).
139+
✅ No PII/secrets in logs.
140+
✅ Correct level semantics (Trace/Debug/Info/Warning/Error/Critical).
141+
✅ Prefer injecting `ILogger<T>`; avoid static loggers.
142+
143+
---
144+
145+
## 9. Error Handling
146+
147+
✅ Centralized exception→response mapping (middleware/filter).
148+
✅ Never swallow exceptions—wrap with context or let propagate.
149+
✅ User-friendly external messages; technical details logged internally.
150+
✅ Use RFC7807 Problem Details where appropriate.
151+
152+
---
153+
154+
## 10. Constants & Magic Strings
155+
156+
✅ Centralize non-trivial strings & numeric literals in `Constants`/`WellKnown`.
157+
✅ Comment rationale for timeouts, cache durations, retry counts.
158+
✅ Avoid scattering duplicate values.
159+
160+
---
161+
162+
## 11. Async & Concurrency
163+
164+
✅ All I/O-bound operations async.
165+
✅ Honor `CancellationToken` quickly.
166+
✅ Avoid shared mutable state; where needed protect with locks/concurrent collections.
167+
✅ Use `ConfigureAwait(false)` only in library layers not relying on context.
168+
169+
---
170+
171+
## 12. UI / XAML (Applicable Projects)
172+
173+
✅ Minimize code-behind; logic in ViewModels.
174+
✅ Use bindings/observables for state propagation.
175+
✅ Avoid manual dispatcher usage unless necessary.
176+
177+
---
178+
179+
## 13. Security & Reliability
180+
181+
✅ No secrets in code; use config/secret providers.
182+
✅ Validate input before persistence/external calls.
183+
✅ Favor idempotency for retry scenarios.
184+
✅ Define timeouts/retry policies explicitly for outbound operations.
185+
186+
---
187+
188+
## 14. Pull Request (Agent) Checklist
189+
190+
- [ ] Release build: zero warnings/errors.
191+
- [ ] Tests added for new/changed logic (list names).
192+
- [ ] No unjustified additions to `<NoWarn>`.
193+
- [ ] SOLID + separation of concerns respected.
194+
- [ ] DTOs validated; mapping tested.
195+
- [ ] Structured logging; no sensitive data.
196+
- [ ] Error handling consistent (middleware/filter updated if needed).
197+
- [ ] No magic strings (constants added where needed).
198+
- [ ] Performance considerations documented if hot path changed.
199+
- [ ] Documentation updated (README / XML comments / changelog if needed).
200+
201+
---
202+
203+
## 15. Agent Prompting Guidance
204+
205+
Provide explicit constraints to reduce refactor churn:
206+
207+
1. Specify layer (e.g. service, controller, repository, ViewModel).
208+
2. Define method contract (inputs, outputs, errors).
209+
3. Request tests inline with implementation.
210+
4. State performance expectations (no extra allocations, single pass).
211+
5. Indicate error strategy (guard clauses vs. exceptions).
212+
213+
Example:
214+
> Create `IUserProfileService` (scoped) with `Task<UserProfileDto?> GetAsync(Guid id, CancellationToken ct)` and `Task UpdateAsync(UpdateUserProfileDto dto, CancellationToken ct)`. Use DI, structured logging, validation (FluentValidation), guard clauses, and add xUnit tests (happy path + not found + validation failure).
215+
216+
---
217+
218+
## 16. Definition of Done
219+
220+
1. Release build warning-free.
221+
2. Tests added & passing (including full suite).
222+
3. Principles & conventions adhered to.
223+
4. No unjustified performance regressions.
224+
5. Checklist completed.
225+
226+
---
227+
228+
## 17. Exceptions Process
229+
230+
If a guideline cannot be met:
231+
232+
- Constraint
233+
- Impact
234+
- Mitigation / follow-up issue reference
235+
236+
Unexplained deviations block merge.
237+
238+
---
239+
240+
## 18. Quick Reference Table
241+
242+
| Area | Rule |
243+
|------|------|
244+
| Build | Release: zero warnings (TreatWarningsAsErrors) |
245+
| Tests | New behavior + edge case |
246+
| SOLID | All five applied |
247+
| Allocations | Minimize hot paths |
248+
| Logging | Structured; no PII |
249+
| Errors | Central mapping; friendly messages |
250+
| DI | Correct lifetimes, constructor injection |
251+
| Constants | Centralize and document |
252+
| Validation | Before processing/persisting |
253+
| Async | Honor cancellation; avoid blocking |
254+
255+
---
256+
257+
## 19. Source Control
258+
- Commit messages: clear, imperative, reference issues.
259+
- MUST follow Conventional Commits format. Bullet points, no big walls of text.
260+
261+
---
262+
263+
## 20. Final Note
264+
265+
Agents must act deterministically and transparently. This document is the authoritative guardrail—adhere strictly to sustain maintainability, reliability, and trust.
266+
267+
---
268+
269+
(End of AGENTS Instructions)

0 commit comments

Comments
 (0)