Skip to content

Commit 3a4982a

Browse files
feat: Add new skill for creating physics quantity types with metadata-driven process
1 parent e034c71 commit 3a4982a

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

  • .claude/skills/add-physics-quantity
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
name: add-physics-quantity
3+
description: Add a new physics quantity type with units, dimensions, operators, and tests to the source-generated system
4+
disable-model-invocation: true
5+
---
6+
7+
# Add Physics Quantity
8+
9+
Add a new physics quantity to the source-generated physics system. This is a fully metadata-driven process - no C# code needs to be written manually.
10+
11+
## Required Information
12+
13+
Before starting, gather from the user:
14+
1. **Quantity name** (e.g., "Viscosity", "MagneticFlux")
15+
2. **Physical dimension symbol** (e.g., "M L⁻¹ T⁻¹")
16+
3. **Dimensional formula** (exponents for mass, length, time, temperature, current, amount, luminosity)
17+
4. **SI unit name and symbol** (e.g., "Pascal" / "Pa")
18+
5. **Which vector forms** are needed (magnitude only, or 1D/2D/3D/4D)
19+
6. **Physics relationships** - what other quantities multiply/divide to produce this one
20+
7. **Any semantic overloads** (named aliases like Weight for ForceMagnitude)
21+
22+
## Steps
23+
24+
### Step 1: Add Dimension to dimensions.json
25+
26+
**File**: `Semantics.SourceGenerators/Metadata/dimensions.json`
27+
28+
Add a new entry to the `physicalDimensions` array following the existing pattern. Each dimension needs:
29+
- `name`: PascalCase dimension name
30+
- `symbol`: Unicode dimension symbol
31+
- `dimensionalFormula`: object with exponents for base dimensions
32+
- `availableUnits`: array of unit names (must match units.json entries)
33+
- `quantities`: object defining vector forms (vector0 = magnitude, vector1-4 = directional)
34+
- `integrals`: array of `{other, result}` pairs where `Self * Other = Result`
35+
- `derivatives`: array of `{other, result}` pairs where `Self / Other = Result`
36+
- `dotProducts`: array for dot product relationships (vector forms only)
37+
- `crossProducts`: array for cross product relationships (vector3 forms only)
38+
39+
**Important**: The generator automatically creates inverse operators. If you define `Force * Length = Energy` on Force, the generator also creates `Energy / Length = Force` and `Energy / Force = Length` on Energy.
40+
41+
### Step 2: Add Units to units.json (if new units needed)
42+
43+
**File**: `Semantics.SourceGenerators/Metadata/units.json`
44+
45+
Add unit entries to the appropriate `unitCategories` entry, or create a new category. Each unit needs:
46+
- `name`: PascalCase unit name
47+
- `symbol`: unit symbol string
48+
- `description`: brief description
49+
- `system`: one of "SIBase", "SIDerived", "Imperial", "USCustomary", "CGS", "Other"
50+
51+
### Step 3: Add Conversions to conversions.json (if non-SI units exist)
52+
53+
**File**: `Semantics.SourceGenerators/Metadata/conversions.json`
54+
55+
Add conversion factor entries for converting between unit systems. Each factor needs:
56+
- `name`: descriptive PascalCase name (e.g., "CalorieToJoules")
57+
- `description`: includes the exact numeric value
58+
- `value`: string representation of the conversion factor
59+
60+
### Step 4: Add Physical Constants to domains.json (if applicable)
61+
62+
**File**: `Semantics.SourceGenerators/Metadata/domains.json`
63+
64+
If the quantity involves physical constants, add them to the relevant domain entry.
65+
66+
### Step 5: Build and Verify
67+
68+
```bash
69+
cd Semantics.Quantities && dotnet build
70+
```
71+
72+
The source generator will create:
73+
- Quantity classes for each vector form in `Generated/`
74+
- Updated `PhysicalDimensions.g.cs` with dimension metadata
75+
- Updated `Units.g.cs` with unit definitions
76+
- Operator overloads for all defined physics relationships
77+
78+
### Step 6: Run Tests
79+
80+
```bash
81+
dotnet test
82+
```
83+
84+
Verify all existing tests still pass and the new quantity types are correctly generated.
85+
86+
## Validation Checklist
87+
88+
- [ ] Dimensional formula exponents sum correctly for the physical dimension
89+
- [ ] Physics relationships are dimensionally consistent (check both sides of equations)
90+
- [ ] Inverse operators are NOT manually added (generator handles them automatically)
91+
- [ ] Unit symbols follow standard conventions
92+
- [ ] `availableUnits` entries match `units.json` unit names exactly
93+
- [ ] No circular dependencies in physics relationships

0 commit comments

Comments
 (0)