Skip to content

Commit 70715e7

Browse files
committed
Migrate to AGENTS.md
1 parent a49093d commit 70715e7

5 files changed

Lines changed: 140 additions & 134 deletions

File tree

.claude/criteria-for-adding-quantities-and-units.md renamed to .agents/criteria-for-adding-quantities-and-units.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ Ask for justification and use cases if this is not clear.
2424

2525
### Avoid X-per-Y units
2626

27-
There are many variations of unit A over unit B, such as `LengthPerAngle` and we want to avoid adding these unless they are very common.
27+
There are many variations of unit A over unit B, such as `LengthPerAngle` and we want to avoid adding these unless they are very common.

.github/workflows/claude-code-review.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- Breaking changes, if any
4242
- Style and conventions
4343
- New quantities or units
44-
- See `.claude/pr-review-instructions.md` for guidance and criteria, they should be widely used and well defined
44+
- See `.agents/criteria-for-adding-quantities-and-units.md` for guidance and criteria, they should be widely used and well defined
4545
- If it seems domain specific or obscure we ask for justification and use cases
4646
- Changes to generated code
4747
- Focus feedback on changes to code generators

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,4 @@ Artifacts
262262

263263
# Claude Code assistant
264264
.claude/settings.local.json
265+
.claude/worktrees/

AGENTS.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# AGENTS.md
2+
3+
This file provides shared guidance for AI coding agents when working with code in this repository.
4+
5+
## Project Overview
6+
7+
UnitsNet is a .NET library that provides strongly-typed physical units and quantities, enabling safe and intuitive unit conversions in code. The library uses code generation from JSON definitions to create type-safe APIs for over 130 physical quantities.
8+
9+
## Key Commands
10+
11+
### Build and Test
12+
- **Build project**: `build.bat` or `dotnet build UnitsNet.slnx`
13+
- **Build all targets** (including nanoFramework): `build-all-targets.bat`
14+
- **Run tests**: `test.bat` or `dotnet test UnitsNet.slnx`
15+
- **Run single test**: `dotnet test UnitsNet.Tests --filter "FullyQualifiedName~TestClassName.TestMethodName"`
16+
- **Clean artifacts**: `clean.bat`
17+
18+
### Code Generation
19+
- **Generate code from JSON definitions**: `generate-code.bat` or `dotnet run --project CodeGen`
20+
- Always run this after modifying any JSON files in `Common/UnitDefinitions/`
21+
- The generator reads 131 JSON definition files and creates C# code
22+
23+
### Development Workflow
24+
1. Modify unit definitions in `Common/UnitDefinitions/*.json`
25+
2. Run `generate-code.bat` to regenerate C# code
26+
3. Run `build.bat` to compile and test
27+
4. Use `test.bat` for isolated test runs
28+
29+
## Code Architecture
30+
31+
### Project Structure
32+
- **UnitsNet/**: Main library with quantity types and units
33+
- `GeneratedCode/`: Auto-generated from JSON definitions (do not edit manually)
34+
- `CustomCode/`: Hand-written code extending generated types
35+
- **UnitsNet.Tests/**: Comprehensive test suite
36+
- **CodeGen/**: Code generation tool that creates C# from JSON definitions
37+
- **Common/UnitDefinitions/**: 131 JSON files defining physical quantities
38+
- **UnitsNet.NumberExtensions/**: Extension methods for numeric types
39+
- **UnitsNet.Serialization.*/**: JSON.NET and System.Text.Json serialization support
40+
- **UnitsNet.NanoFramework/**: Support for embedded .NET nanoFramework
41+
42+
### Code Generation Process
43+
The project uses a sophisticated code generation system:
44+
1. JSON definitions in `Common/UnitDefinitions/` describe units, conversions, and localizations
45+
2. `CodeGen` project processes these to generate:
46+
- Quantity types (e.g., `Length`, `Mass`)
47+
- Unit enums (e.g., `LengthUnit`, `MassUnit`)
48+
- Conversion logic and unit abbreviations
49+
3. Generated code goes to `*/GeneratedCode/` folders
50+
4. Custom code in `*/CustomCode/` extends generated types
51+
52+
### Key Classes and Patterns
53+
- **IQuantity**: Base interface for all quantity types
54+
- **Quantity**: Static class for dynamic quantity operations
55+
- **UnitConverter**: Handles conversions between units
56+
- **QuantityParser/UnitParser**: Parse strings to quantities/units
57+
- **UnitsNetSetup**: Configuration singleton
58+
59+
### Adding or Modifying Units
60+
1. Edit or create JSON file in `Common/UnitDefinitions/`
61+
2. Follow conversion function guidelines in [Docs/adding-a-new-unit.md](Docs/adding-a-new-unit.md):
62+
- Use multiplication for `FromUnitToBaseFunc`
63+
- Use division for `FromBaseToUnitFunc`
64+
- Prefer scientific notation (1e3, 1e-5)
65+
- Use exact constituent constants instead of pre-computed decimals
66+
3. Run `generate-code.bat`
67+
4. Add tests if needed
68+
69+
## Important Conventions
70+
71+
### Coding Standards
72+
- Follow `.editorconfig` specifications
73+
- Use ReSharper settings in `UnitsNet.sln.DotSettings`
74+
- Treat warnings as errors (except obsolete warnings)
75+
- Add file headers to new files
76+
77+
### Unit Definition Rules
78+
- Base units are chosen for each quantity (e.g., meter for Length)
79+
- All conversions go through the base unit
80+
- Use superscript in abbreviations: cm², m³
81+
- Compound units format: N·m (dot), km/h (slash)
82+
83+
### Testing
84+
- Test class naming: `<Type>Tests`
85+
- Test method naming: `<method>_<condition>_<result>`
86+
- Tests accept error margin of 1E-5 for most units
87+
88+
## Special Considerations
89+
90+
### .NET nanoFramework Support
91+
- Separate projects for nanoFramework compatibility
92+
- Use `build-all-targets.bat` to include nanoFramework builds
93+
- Limited feature set compared to full .NET
94+
95+
### Performance
96+
- Conversion functions are compiled to delegates for performance
97+
- All conversions go through base units (potential for small errors)
98+
- Precision goal is 1E-5 for most units
99+
100+
### Localization
101+
- Unit abbreviations support multiple cultures
102+
- JSON definitions include translations for various languages
103+
- Default culture: Thread.CurrentCulture, fallback to en-US
104+
105+
## Common Tasks
106+
107+
### Find specific quantity or unit implementation
108+
- Quantity types: `UnitsNet/GeneratedCode/Quantities/*.g.cs`
109+
- Unit enums: `UnitsNet/GeneratedCode/Units/*.g.cs`
110+
- Custom extensions: `UnitsNet/CustomCode/Quantities/*.extra.cs`
111+
- Unit definitions: `Common/UnitDefinitions/*.json`
112+
113+
### Debug code generation
114+
- Generator entry: `CodeGen/Program.cs`
115+
- Generator logic: `CodeGen/Generators/`
116+
- Enable verbose logging: Check Serilog configuration in Program.cs
117+
118+
### Run performance benchmarks
119+
- Execute: `dotnet run -c Release --project UnitsNet.Benchmark`
120+
- Results saved to `Artifacts/` folder
121+
122+
## Documentation
123+
124+
All contributor and user documentation lives in [Docs/](Docs/README.md), including:
125+
- [Adding a New Unit](Docs/adding-a-new-unit.md) - step-by-step guide with JSON schema conventions
126+
- [Adding Operator Overloads](Docs/adding-operator-overloads.md)
127+
- [Precision](Docs/precision.md) - conversion precision and test value guidelines
128+
- [Serialization](Docs/serialization.md), [String Formatting](Docs/string-formatting.md), [Saving to Database](Docs/saving-to-database.md)
129+
- [Upgrade Guides](Docs/README.md#upgrade-guides) for major version migrations
130+
131+
## Pull request reviews
132+
133+
### Adding new quantities or units
134+
135+
See `.agents/criteria-for-adding-quantities-and-units.md` for instructions on adding new quantities or units to ensure they are widely used and well defined.

CLAUDE.md

Lines changed: 2 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,5 @@
11
# CLAUDE.md
22

3-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
3+
@AGENTS.md
44

5-
## Project Overview
6-
7-
UnitsNet is a .NET library that provides strongly-typed physical units and quantities, enabling safe and intuitive unit conversions in code. The library uses code generation from JSON definitions to create type-safe APIs for over 130 physical quantities.
8-
9-
## Key Commands
10-
11-
### Build and Test
12-
- **Build project**: `build.bat` or `dotnet build UnitsNet.slnx`
13-
- **Build all targets** (including nanoFramework): `build-all-targets.bat`
14-
- **Run tests**: `test.bat` or `dotnet test UnitsNet.slnx`
15-
- **Run single test**: `dotnet test UnitsNet.Tests --filter "FullyQualifiedName~TestClassName.TestMethodName"`
16-
- **Clean artifacts**: `clean.bat`
17-
18-
### Code Generation
19-
- **Generate code from JSON definitions**: `generate-code.bat` or `dotnet run --project CodeGen`
20-
- Always run this after modifying any JSON files in `Common/UnitDefinitions/`
21-
- The generator reads 131 JSON definition files and creates C# code
22-
23-
### Development Workflow
24-
1. Modify unit definitions in `Common/UnitDefinitions/*.json`
25-
2. Run `generate-code.bat` to regenerate C# code
26-
3. Run `build.bat` to compile and test
27-
4. Use `test.bat` for isolated test runs
28-
29-
## Code Architecture
30-
31-
### Project Structure
32-
- **UnitsNet/**: Main library with quantity types and units
33-
- `GeneratedCode/`: Auto-generated from JSON definitions (do not edit manually)
34-
- `CustomCode/`: Hand-written code extending generated types
35-
- **UnitsNet.Tests/**: Comprehensive test suite
36-
- **CodeGen/**: Code generation tool that creates C# from JSON definitions
37-
- **Common/UnitDefinitions/**: 131 JSON files defining physical quantities
38-
- **UnitsNet.NumberExtensions/**: Extension methods for numeric types
39-
- **UnitsNet.Serialization.*/**: JSON.NET and System.Text.Json serialization support
40-
- **UnitsNet.NanoFramework/**: Support for embedded .NET nanoFramework
41-
42-
### Code Generation Process
43-
The project uses a sophisticated code generation system:
44-
1. JSON definitions in `Common/UnitDefinitions/` describe units, conversions, and localizations
45-
2. `CodeGen` project processes these to generate:
46-
- Quantity types (e.g., `Length`, `Mass`)
47-
- Unit enums (e.g., `LengthUnit`, `MassUnit`)
48-
- Conversion logic and unit abbreviations
49-
3. Generated code goes to `*/GeneratedCode/` folders
50-
4. Custom code in `*/CustomCode/` extends generated types
51-
52-
### Key Classes and Patterns
53-
- **IQuantity**: Base interface for all quantity types
54-
- **Quantity**: Static class for dynamic quantity operations
55-
- **UnitConverter**: Handles conversions between units
56-
- **QuantityParser/UnitParser**: Parse strings to quantities/units
57-
- **UnitsNetSetup**: Configuration singleton
58-
59-
### Adding or Modifying Units
60-
1. Edit or create JSON file in `Common/UnitDefinitions/`
61-
2. Follow conversion function guidelines in [Docs/adding-a-new-unit.md](Docs/adding-a-new-unit.md):
62-
- Use multiplication for `FromUnitToBaseFunc`
63-
- Use division for `FromBaseToUnitFunc`
64-
- Prefer scientific notation (1e3, 1e-5)
65-
- Use exact constituent constants instead of pre-computed decimals
66-
3. Run `generate-code.bat`
67-
4. Add tests if needed
68-
69-
## Important Conventions
70-
71-
### Coding Standards
72-
- Follow `.editorconfig` specifications
73-
- Use ReSharper settings in `UnitsNet.sln.DotSettings`
74-
- Treat warnings as errors (except obsolete warnings)
75-
- Add file headers to new files
76-
77-
### Unit Definition Rules
78-
- Base units are chosen for each quantity (e.g., meter for Length)
79-
- All conversions go through the base unit
80-
- Use superscript in abbreviations: cm², m³
81-
- Compound units format: N·m (dot), km/h (slash)
82-
83-
### Testing
84-
- Test class naming: `<Type>Tests`
85-
- Test method naming: `<method>_<condition>_<result>`
86-
- Tests accept error margin of 1E-5 for most units
87-
88-
## Special Considerations
89-
90-
### .NET nanoFramework Support
91-
- Separate projects for nanoFramework compatibility
92-
- Use `build-all-targets.bat` to include nanoFramework builds
93-
- Limited feature set compared to full .NET
94-
95-
### Performance
96-
- Conversion functions are compiled to delegates for performance
97-
- All conversions go through base units (potential for small errors)
98-
- Precision goal is 1E-5 for most units
99-
100-
### Localization
101-
- Unit abbreviations support multiple cultures
102-
- JSON definitions include translations for various languages
103-
- Default culture: Thread.CurrentCulture, fallback to en-US
104-
105-
## Common Tasks
106-
107-
### Find specific quantity or unit implementation
108-
- Quantity types: `UnitsNet/GeneratedCode/Quantities/*.g.cs`
109-
- Unit enums: `UnitsNet/GeneratedCode/Units/*.g.cs`
110-
- Custom extensions: `UnitsNet/CustomCode/Quantities/*.extra.cs`
111-
- Unit definitions: `Common/UnitDefinitions/*.json`
112-
113-
### Debug code generation
114-
- Generator entry: `CodeGen/Program.cs`
115-
- Generator logic: `CodeGen/Generators/`
116-
- Enable verbose logging: Check Serilog configuration in Program.cs
117-
118-
### Run performance benchmarks
119-
- Execute: `dotnet run -c Release --project UnitsNet.Benchmark`
120-
- Results saved to `Artifacts/` folder
121-
122-
## Documentation
123-
124-
All contributor and user documentation lives in [Docs/](Docs/README.md), including:
125-
- [Adding a New Unit](Docs/adding-a-new-unit.md) — step-by-step guide with JSON schema conventions
126-
- [Adding Operator Overloads](Docs/adding-operator-overloads.md)
127-
- [Precision](Docs/precision.md) — conversion precision and test value guidelines
128-
- [Serialization](Docs/serialization.md), [String Formatting](Docs/string-formatting.md), [Saving to Database](Docs/saving-to-database.md)
129-
- [Upgrade Guides](Docs/README.md#upgrade-guides) for major version migrations
130-
131-
## Pull request reviews
132-
133-
### Adding new quantities or units
134-
135-
See `.claude/criteria-for-adding-quantities-and-units.md` for instructions on adding new quantities or units to ensure they are widely used and well defined.
5+
Follow the shared repository guidance in `AGENTS.md`.

0 commit comments

Comments
 (0)